question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

  1. Install packages
  2. Run pnpm run vitest
  3. See error, because it imports the wrong preact lib

Expected behavior No error

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
rschristiancommented, Jun 14, 2022

I don’t mean inconsistency in that way. I know perfectly well why you have both module and exports.import with different files there. Inconsistency comes when you don’t have the same in your subpackages.

Sorry, I thought you were referring to the previous sentence with that comment:

If it’s correct then why preact references preact/hook/hook.mjs instead of the “correct” module entry?

0reactions
sheremet-vacommented, Jun 14, 2022

It’s not “inconsistent” as they’re two different things.

I don’t mean inconsistency in that way. I know perfectly well why you have both module and exports.import with different files there. Inconsistency comes when you don’t have the same in your subpackages.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found