-
-
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
Please remove process.env.NODE_ENV
in dist/immer.mjs
#1141
Comments
That inclusion is intentional, and Vite should be replacing it automatically. |
This problem is not only about Vite, and this is typically not happening with other packages. As an example, using |
I'm not familiar with how JSPM resolves which file to use inside of an NPM package, but if you need to use it in a browser directly you should be pointing it to |
JSPM is an import maps first approach to package management so it does support development builds and production builds, so the true solution might not be as simple as to just say "use production builds if you want the Node environment stuff stripped out". However, I believe JSPM will respect the
You can read more here: https://nodejs.org/api/packages.html#conditional-exports Basically this would be the most official way to say "for Node environments we use this entry point, otherwise we use this other one". For Immer, which already uses {
// ...
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/immer.d.ts",
"node": {
"import": "./dist/immer.mjs",
"require": "./dist/cjs/index.js"
},
"default": "./dist/immer.production.mjs"
}
},
// ...
} Now like I implied initially, this would hide the development version from JSPM (which would be useful if you want to have a bundler-less browser first environment with development support, like we did at Framer which is completely ES Modules + Import Maps based). But from what I can see, there is no Now I'm not sure what @guybedford's stance is on these kinds of situations – for example esm.sh appears to have taken another approach where it doesn't include the |
JSPM will replace What we do for CommonJS is effectively build two files - one with the dev and one with the production condition, and then set up entry conditions to those variations depending on which mode the package is loaded. It's a little messy, and doing this explicitly at the package level is the preferred model (using the This is mostly a principled stance in JSPM though which we can change anytime, so if there is strong resistance to moving away from As for using {
"main": "./dist/cjs/index.js",
"module": "./dist/immer.legacy-esm.js",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/immer.d.ts",
"import": "./dist/immer.mjs",
"require": "./dist/cjs/index.js"
}
},
"jsnext:main": "dist/immer.mjs",
"react-native": "./dist/immer.legacy-esm.js"
} Adding a |
Sure, makes sense. Immer isn't my package, but I did contribute the packaging setup based on what I was working on for the Redux libraries. File a PR here? |
🚀 Feature Proposal
I use
import { produce } from 'immer'
in vite project. After building,process.env.NODE_ENV
is still in my built file.Motivation
Could
process.env.NODE_ENV
be removed indist/immer.mjs
?The text was updated successfully, but these errors were encountered: