protomaps / protomaps-leaflet

Lightweight vector map rendering + labeling and symbology for Leaflet
https://protomaps.com/docs/frontends/leaflet
BSD 3-Clause "New" or "Revised" License
767 stars 43 forks source link

Can't resolve internal file imports in distribution package #158

Closed claustres closed 3 months ago

claustres commented 4 months ago

Switching from v1 to v3 in an app using WebPack but without using TS I struggled with import errors like this: image

It appears that the missing .js extension of the import statements in the dist folder get WebPack messy. Just to confirm the issue I used https://github.com/beenotung/fix-esm-import-path to fix it like this fix-esm-import-path node_modules/protomaps-leaflet/dist/index.js. However, I am not a TS gourou so I guess there is a compile option to do so as it would ease integration.

claustres commented 4 months ago

I made some research and it seems that the best thing to do is to specify file extension at the source level (ie TypeScript) otherwise you have to use the kind of hacking tool I used like babel plugins or so.

bdon commented 4 months ago

Can you create and share a minimal WebPack example that reproduces your problem without TypeScript?

claustres commented 4 months ago

Probably not so easy but I can first share the setup of our application, which is based on Quasar Webpack support.

bdon commented 4 months ago

We're likely going to migrate the build scripts to https://github.com/egoist/tsup which should improve the CommonJS situation, and also stop using default exports.

bdon commented 3 months ago

Can you please try 4.0.0-alpha.0

claustres commented 3 months ago

It seems to work fine now @bdon, thanks. Let me know when you plan to release a fix.

bdon commented 3 months ago

This major release will also move from bundled ESM modules/CJS to unbundled, which is what people expect for ES6 frontend and NodeJS projects. Waiting on https://github.com/protomaps/protomaps-leaflet/issues/162#issuecomment-2250641439 to see that there is a workable resolution for ESM-in-the-browser.

bdon commented 3 months ago

v4.0.0 released: https://www.npmjs.com/package/protomaps-leaflet