Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript cannot resolve module due to "exports" in package.json #280

Closed
gvkhna opened this issue Aug 26, 2024 · 4 comments · Fixed by #286
Closed

Typescript cannot resolve module due to "exports" in package.json #280

gvkhna opened this issue Aug 26, 2024 · 4 comments · Fixed by #286

Comments

@gvkhna
Copy link

gvkhna commented Aug 26, 2024

Hey, great plugin!

I see you're trying to integrate this into maplibre, that would be amazing. I'm encountering a small issue with typescript where by default my setup is not able to resolve the module. It's due to this part of the package.json

 "exports": {
    "module": "./dist/index.mjs",
    "require": "./dist/index.cjs"
  },

which is incorrect for a esm module AFAIK. Once I remove that indeed typescript finds it right away. As well I ran tsc --traceResolution and it points to

Entering conditional exports.
Saw non-matching condition 'module'.
Saw non-matching condition 'require'.

Can this small issue be fixed? I'm surprised I seem to be the only one having the issue perhaps I'm missing something in my tsconfig json?

{
  "extends": "astro/tsconfigs/base",
  "compilerOptions": {
    "noErrorTruncation": false,
    "baseUrl": ".",
    "esModuleInterop": true,
    "jsx": "react-jsx",
    "module": "ESNext",
    "allowSyntheticDefaultImports": true,
    "strictNullChecks": true,
    "target": "ESNext",
    "paths": {
      ...
    }
  },
  "include": ["types.d.ts", "src/**/*.ts", "src/**/*.tsx", "src/**/*.astro"],
  "exclude": ["node_modules"]
}

Thanks!

@onthegomap onthegomap deleted a comment Aug 26, 2024
@gvkhna
Copy link
Author

gvkhna commented Aug 26, 2024

i did find this simple work around

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "maplibre-contour": ["node_modules/maplibre-contour/dist/index"]
    }
  }
}

@msbarry
Copy link
Contributor

msbarry commented Aug 27, 2024

Thanks for pointing this out @gvkhna! I'm trying to reproduce different setups people might use in the test-project-* directories so that CI can confirm that they each build successfully. Any chance you could start a PR that reproduces the error you're seeing with a minimal test project? It might be require a new test project, or possibly run an extra command in one of the existing test projects?

@msbarry
Copy link
Contributor

msbarry commented Aug 27, 2024

This tool also reports a couple of other issues with the package.json: https://publint.dev/maplibre-contour@0.0.7

@gvkhna
Copy link
Author

gvkhna commented Aug 27, 2024

This tool also reports a couple of other issues with the package.json: https://publint.dev/maplibre-contour@0.0.7

Awesome tool I didn't know about. Nice find!

Can confirm this solves the problem on my end as it recommends.

  "exports": {
    "module": "./dist/index.mjs",
    "require": "./dist/index.cjs",
    "types": "./dist/index.d.ts"
  },

Adding the types lets typescript find it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@gvkhna @msbarry and others