Add `exports` field to subpackages to align module resolution with the root level `package.json`
See original GitHub issue- Check if updating to the latest Preact version resolves the issue
Describe the bug
While working on https://github.com/vitest-dev/vitest/issues/737 I found that preact/hooks
module
entry points to cjs package instead of hooks.mjs
. Is this intentional?
If I change it to .mjs
everything works fine. Usually Vitest doesn’t resolve what is stored in main
field, but it is configurable with resolve.mainFields
Vite option (this is what Svelte is doing).
So, I guess Vite prioritizes closest package.json
resolvings instead of root level package exports
.
Might be related: https://github.com/preactjs/preset-vite/issues/52
To Reproduce
Reproduction: https://github.com/molily/vitest-test/tree/preact-and-svelte
- Install packages
- Run
pnpm run vitest
- See error, because it imports the wrong preact lib
Expected behavior No error
Issue Analytics
- State:
- Created a year ago
- Comments:19 (9 by maintainers)
Top Results From Across the Web
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 >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 >How can I use "exports" in package.json today for nested ...
I've been looking to use nested folders for a design system package we created at Pipefy, and after deep research, I found how...
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 >Best practices for creating a modern npm package - Snyk
The moduleResolution property helps TypeScript to figure out how an ... Update your package.json file with an exports field to define how to ......
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
Sorry, I thought you were referring to the previous sentence with that comment:
I don’t mean inconsistency in that way. I know perfectly well why you have both
module
andexports.import
with different files there. Inconsistency comes when you don’t have the same in your subpackages.