-
Notifications
You must be signed in to change notification settings - Fork 156
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
Fix exports map to support loading in Node esm #425
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spotting this, really appreciate it!
package.json
Outdated
"module": "dist/preact-router.module.js", | ||
"jsnext:main": "dist/preact-router.module.js", | ||
"module": "dist/preact-router.mjs", | ||
"jsnext:main": "dist/preact-router.mjs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we revert this? It might be overly cautious, but there's no (functional) reason to subject these to Node's extension semantics, as Node never reads them. As unlikely as it is to be an issue, there are some older tools that will read "module"
but will trip over .mjs
, making this a breaking change.
A post-build cp
to .mjs
(if I'm remembering Microbundle's key preference right) would be sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point! 👍 Another way to fix this without modifying the filenames at all would be to add "type": "module"
. Maybe this would be even safer? And we would not need to copy the files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"type": "module"
would necessitate that all CJS entries switch to .cjs
, which has even less support.
.mjs
got some popularity and use a few years before .cjs
& the current Node extension semantics were specc'd and solidified.
Okay, you mean there are Node.js versions that support the "type" field but
no exports maps? Or do you refer to bundlers that might also have adapted
Node's file extension scheme but neither support the "module" field nor
export maps? I had naively assumed, that all tools that know how to
interprete the "type" field also support at least one way to specify
CommonJS fallbacks. But I totally agree to play it safe here 👍
Ryan Christian ***@***.***> schrieb am Do., 26. Mai 2022,
00:07:
… ***@***.**** commented on this pull request.
------------------------------
In package.json
<#425 (comment)>
:
> - "module": "dist/preact-router.module.js",
- "jsnext:main": "dist/preact-router.module.js",
+ "module": "dist/preact-router.mjs",
+ "jsnext:main": "dist/preact-router.mjs",
"type": "module" would necessitate that all CJS entries switch to .cjs,
which has even less support.
.mjs got some popularity and use a few years before .cjs & the current
Node extension semantics were specc'd and solidified.
—
Reply to this email directly, view it on GitHub
<#425 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAV22XA5W4YAUAMR3SOEKTVL2QCJANCNFSM5W2ADQ2A>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
There's a few odd Node versions that have some issues around The issue is that bundlers have consumed So it's best to keep those newer extensions locked behind In this case, we add |
I updated the branch so that only the "module" exports use the |
Silly issue; somehow the test suite picks up and uses the new |
Thanks for putting this together! |
It was a pleasure. Are there any plans for a new release on npm? |
@rschristian would be really nice if this could be published to npm... i currently cant upgrade my projects to "true" esm due to this.,.. |
@lohfu Would probably recommend |
Jovi released v4.1.0 earlier today which includes this PR. Hope it helps! |
@rschristian cheers! |
Currently, preact-router fails to load in Node.js when it is imported from an ES module. Node correctly picks up the
.module.js
version as specified in the exports map, but loads it as cjs module because of the file extension. Here is a simple StackBlitz example that shows the current behavior.This PR fixes the problem by changing the file extension to
.mjs
.