onthegomap / maplibre-contour

Render contour lines from raster DEM tiles in maplibre-gl-js
https://onthegomap.github.io/maplibre-contour/
Other
155 stars 15 forks source link

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

Closed gvkhna closed 2 weeks ago

gvkhna commented 2 weeks ago

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!

gvkhna commented 2 weeks ago

i did find this simple work around

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "maplibre-contour": ["node_modules/maplibre-contour/dist/index"]
    }
  }
}
msbarry commented 2 weeks ago

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 commented 2 weeks ago

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

gvkhna commented 2 weeks ago

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.