Closed gaomeng1900 closed 1 year ago
You are probably importing the wrong file, please check the other files available in dist.
On Fri, 5 May 2023, 14:12 Simon ยท ่ฅฟ่, @.***> wrote:
๐ Bug Report
I have been using Immer in the browser with native ESM environment. Everything was fine. After upgrading Immer to v10.0.1. I got a ReferenceError: process is not defined error.
The error is caused by:
// src/utils/errors.tsvar errors = process.env.NODE_ENV !== "production" ? [
in dist/immer.mjs.
process.env.NODE_ENV assume that there is a bundler that handles common NodeJS environment vars which are no parts of JS or ESM or browser specs.
My suggestion is that if we decide to respect ESM spec. Make NODE_ENV optional. If not. Make a declaration in the document that certain polyfills are neccessary. Link to repro
codesandbox https://codesandbox.io/s/happy-tharp-6dgzl8?file=/index.html To Reproduce
See codesandbox above. Observed behavior
V9 is ok. V10 got ReferenceError: process is not defined error. Expected behavior
Should not rely on process.env.NODE_ENV. Environment
- chrome 113
- v10.0.1
- I filed this report against the latest version of Immer
- Occurs with setUseProxies(true)
- Occurs with setUseProxies(false) (ES5 only)
โ Reply to this email directly, view it on GitHub https://github.com/immerjs/immer/issues/1046, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN4NBGVTE2A7E3PBKAO6HLXETVDHANCNFSM6AAAAAAXXBA7NI . You are receiving this because you are subscribed to this thread.Message ID: @.***>
@mweststrate You are right. dist/immer.production.mjs
works fine. I updated the codesandbox demo.
const mod = await import("https://unpkg.com/immer@10.0.1/dist/immer.production.mjs");
Works.
Yep, that immer.production.mjs
file was included specifically for this use case, and has the process
checks compiled away.
๐ Bug Report
According to the v10 release note:
But when I import Immer in a native ESM environment. I got a
ReferenceError: process is not defined
error.The error is caused by:
in
dist/immer.mjs
.Link to repro
codesandbox
To Reproduce
See codesandbox above.
Observed behavior
Got
ReferenceError: process is not defined
error.Expected behavior
Should not rely on
process.env.NODE_ENV
.Environment
setUseProxies(true)
setUseProxies(false)
(ES5 only)