package.json: type module, but no exports map
See original GitHub issueDescribe the bug
The ol package specifies in its package.json
that it’s of type module. This means that any folder-style imports like import Map from 'ol/Map';
are prohibited when using it inside a project that itself is of type module. According to the documentation, they should work.
To Reproduce Steps to reproduce the behavior:
- Clone https://github.com/maxicarlos08/sveltekit-ol
npm ci
npm run build
- See error about an invalid directory import
Expected behavior Folder imports should work.
To make them work, you need to add an exports map to your package.json
. Beware though, this means that anything not listed in the exports map is no longer accessible from the outside, so strictly speaking this would be a breaking change.
cc @maxicarlos08 who opened the issue over at https://github.com/sveltejs/kit/issues/3037
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Modules: Packages | Node.js v19.3.0 Documentation
In a package's package. json file, two fields can define entry points for a package: "main" and "exports" . Both fields apply to...
Read more >New package.json `exports` field not working with TypeScript
json field, called exports , to select and rewrite exported files. But Typescript raises the 2307 error, saying that module is not found....
Read more >Node.JS (New) Package.json Exports Field - Medium
The exports field (or “export map”) provides a way to expose your package modules for different environments and JavaScript flavors WHILE ...
Read more >Use `package.json#exports` map · Issue #4155 - GitHub
Hey folks, this is very important: basically Parcel cannot use modules which support both common.js and ESM. We're forced to revert and drop...
Read more >Package exports - webpack
The exports field in the package.json of a package allows to declare which module should be used when using module requests like import...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As mentioned in sveltejs/kit#3037, here is a working
index.svelte
route with no modifications to theol
package (or any other):The key difference between this example and and maxicarlos08/sveltekit-ol:
At some point it may also be possible to
import {OSM} from 'ol/source.js';
(note the file extension). However, it looks like SvelteKit / Vite are also importing all the other modules that are imported and re-exported from theol/source.js
module (perhaps because there may be side effects). The one causing trouble isol/source/GeoTIFF.js
. We can make a change in this library to usePool
etc from the default export of thegeotiff
package, but the source also creates a worker using theBlob
constructor, so it fails in Node.Update: Even if we lazily create resources for the worker (avoiding references to
Blob
on import as in #13115), webpack and Node disagree on how to import things from thegeotiff
package.webpack believes you should
while Node believes you should
Ideally this hardship could be avoided if tools let you completely opt out of SSR (like not even importing modules) for parts of your app that only work in a browser (maybe sveltejs/kit#1650 will bring this).
There will probably continue to be things we can do to support importing ol modules in Node, but I’ll close this for now (I don’t think we need an exports map).