-
-
Notifications
You must be signed in to change notification settings - Fork 852
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: Fix importing ES module from Node.js (#901) #921
Conversation
✅ Deploy Preview for quizzical-lovelace-dcbd6a canceled.
|
"import": "./dist/immer.esm.mjs", | ||
"require": "./dist/index.js" | ||
}, | ||
"./*": "./*" |
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.
I don't think this one is needed; there is nothing else to import in immers case.
Looking good! Would you mind removing the |
While the official usage recommendation of Immer might not include any imports of sub paths, I could imagine that there are some projects that use Immer by importing from If you say that importing sub paths is not a supported use case and thus breaking it is not considered a breaking change, or if the next release will be a major release anyways and thus a breaking change is acceptable, I can remove the wild-card export. In that case, I would also remove the old |
The import
|
Pull Request Test Coverage Report for Build 2089859747Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Merging as is. Typically whenever I touch something ESM related, the skies come tumbling down, so brace yourselves. Should be available as 9.1.0 in ~30 minutes |
Nice! I'm also not 100% sure whether nothing will break, since there are so many module bundlers that handle modules in a different way. I'm curious to find out whether any reports will come in. |
🎉 This PR is included in version 9.0.13 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hello! One such breakage is coming from Redux Tookit, which has an unpinned usage of immer v9.0.13 includes this PR, and breaks with React-Native's Metro module resolution for this package:
Anyone running into this: use |
@MoreSaltMoreLemon I haven't tried the new version yet, but the fact that I was having trouble with redux-toolkit was the original reason why I opened this pull request. I have also opened one with redux-toolkit (reduxjs/redux-toolkit#2200), but it has not been merged yet. The error you are seeing looks strange to me, since the file |
I continued looking into it after my response and tried to recreate in a fresh create-react-native-app, and couldn't. Also couldn't recreate in a regular react-app. It appears that the issue is simply our using an older version of metro which predates .mjs support. Even though the file definitely exists, it isn't able to read it, and consequently tries to append a file extension that it can read to the provided filename and fails. So resolutions are temporarily lock the version to 9.0.12 and update react-native/metro to a newer version with .mjs support. |
Beyond the fields that Node consumes (and therefore requires the It's only going to be an issue in older build tools, but regardless, this change was a semver major. |
So things did break, for immer users but also users of libraries relying on immer (reduxjs/toolkit for one) Shouldn't this be reverted and included in a major change instead ? |
This pull request fixes #901 by publishing the ES module with the
.mjs
file extension.For now, the existing ESM bundle
dist/immer.esm.js
is simply copied todist/immer.esm.mjs
building. This makes sure that there are no breaking changes, just in case any library includes the old file manually. In the next major release of Immer, the old bundle can be removed. By then jaredpalmer/tsdx#1059 might be released, which I believe will adapt the bundle file extensions.This pull request also adds an
exports
field topackage.json
, which will make sure that Node.js will import the ES module when run in ESM mode. The wildcard export"./*": "./*"
will make sure that any sub paths can be continued to be imported (for example something likeimport 'immer/src/immer.ts'
, which makes this a non-breaking change.