immerjs / immer

Create the next immutable state by mutating the current one

Home Page:https://immerjs.github.io/immer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

v10 breaks ESM import.

gaomeng1900 opened this issue Β· comments

commented

πŸ› Bug Report

According to the v10 release note:

Immer is now an ESM package that can be directly imported into the browser. CJS should still work, UMD support has been removed.

But when I import Immer in a native ESM environment. I got a ReferenceError: process is not defined error.

const mod = await import("https://unpkg.com/immer@10.0.1/dist/immer.mjs");

The error is caused by:

// src/utils/errors.ts
var errors = process.env.NODE_ENV !== "production" ? [

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

  • 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)
commented

@mweststrate You are right. dist/immer.production.mjs works fine. I updated the codesandbox demo.

commented
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.