maplibre/maplibre-gl-geocoder

V1.6.0 CJS Support

Closed this issue · 2 comments

Hey all, I noticed after upgrading to 1.6.0 some libraries that previously imported maplibre-gl-geocoder broken due to an error like so

Error: require() of ES Module /Users/thadtrin/workspace/amplify-ui-2/node_modules/@maplibre/maplibre-gl-geocoder/dist/maplibre-gl-geocoder.js from /Users/thadtrin/workspace/amplify-ui-2/node_modules/maplibre-gl-js-amplify/lib/cjs/AmplifyMapLibreGeocoder.js not supported.
maplibre-gl-geocoder.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename maplibre-gl-geocoder.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /Users/thadtrin/workspace/amplify-ui-2/node_modules/@maplibre/maplibre-gl-geocoder/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

It seems like after moving to es6 and adding the rollup configuration the entry point got changed. I believe it may be as simple as removing the type field in the package.json or adding the exports field but haven't had time to test yet.

Rollup is configuring 2 outputs:


But there might be more configuration needed.
Let me know if you need help solving this.

Fixed by #140