-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package.json#exports.browser
does not adhere to Node module type semantics
#4406
Comments
It's an issue others have mentioned before, but ultimately, this is a completely valid configuration we have here and it's other tools that are causing the issue. Using the Additionally, altering Additional references: preactjs/jest-preset-preact#13 (comment), #3634 |
Thanks for the detailed response and additional tickets! Apologies that my cursory search didn't turn them up. I definitely see (and agree with much of) where you're coming from here. Out of curiosity, what are the differences between the
I might quibble with "completely valid configuration" here: For example, I think this would be a more accurate (completely untested) export that says, "here is a {
"exports": {
".": {
"types": "./src/index.d.ts",
"browser": {
"import": "./dist/preact.module.js",
},
"umd": "./dist/preact.umd.js",
"import": "./dist/preact.mjs",
"require": "./dist/preact.js"
},
}
}
I agree with most of this, and I certainly don't think Preact or any module should, when providing a But I think a user should be able to make that choice! For a lot of us, the upsides of running browser-intended code against a fake DOM outweigh the downsides of using an inaccurate environment. So, while no module should go out of their way to support this sort of runtime, I do think a module should accurately report its exports so that a user can choose to do this and take on whatever risk they feel is appropriate.
Yeah, definitely hear this. I saw in one of the threads you linked that this won't be an issue in I wonder, but do not know, if something like my example above would be non-breaking. I'm not sure what tools are currently relying on the |
None at the moment, and I think the latter is even generated from the former. We could make use of this but haven't (not sure if we will either).
Node's docs pretty specifically state it does not govern any keys/conditions that Node itself does not consume which was a key design decision from the start. Additional keys are, per the spec, completely valid and can have their own semantics. At the moment, we do happen to make use of this.
I mean, we do, for the intended environment. If you want to use something in an env it's not meant to run in, there be dragons and all that.
Can't say for sure; v11 has no planned release date at this time (we've gotten a lot more use out of v10 than we originally expected, delaying the need for a new major) and so we might revise our export conditions further before release. The v11 is indeed "up to date", but early beta-ish and things may change.
It might, but with how fragile |
browser
exports not recognized as ESMpackage.json#exports.browser
does not adhere to Node module type semantics
Describe the bug
Hello! I'm coming here from testing-library/svelte-testing-library#381, where a user reported interop issues when using
preact
together with oursvelteTesting
Vite plugin. Our plugin makes one significant change to the Vite config: it addsbrowser
toresolve.conditions
to ensure Svelte's browser code is imported.This also causes Preact's
browser
export -./dist/preact.module.js
- to be used:The bug is:
preact.module.js
is ESMpackage.json
does not specifictype
, so"type": "commonjs"
is impliedpreact.module.js
ends in.js
rather than.mjs
, it is treated as CommonJSAt worst, this produces a fairly inscrutable error:
With enough fiddling, I can get Vite to complain in this manner:
If I go in and manually rename files to
.module.mjs
and update thepackage.json
, everything works happily.To Reproduce
I can put together a minimal reproduction if required - just let me know. There is also this repro from the original reporter: https://github.com/molily/vitest-preact-svelte
Expected behavior
I should be able to load the
browser
copy of Preact in Vitest without issueThe text was updated successfully, but these errors were encountered: