immerjs/immer · error · Error
[Immer] minified error nr: ${error}. Full error at: https://
Error message
[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf What it means
The production-mode throw in die() (src/utils/errors.ts:47-49). When process.env.NODE_ENV === "production", the errors table is replaced with [] (src/utils/errors.ts:39), so the dev branch (and its message strings) is dead-stripped at build time and only this compact branch ships. It discards the formatted text and emits just the numeric code plus a link (https://bit.ly/3cXEKWf, Immer's error docs) to minimize bundle size. The number maps 1:1 to an index in the development errors array.
Source
Thrown at src/utils/errors.ts:47
"Object.defineProperty() cannot be used on an Immer draft",
"Object.setPrototypeOf() cannot be used on an Immer draft",
"Immer only supports deleting array indices",
"Immer only supports setting array indices and the 'length' property",
function (thing: string) {
return `'original' expects a draft, got: ${thing}`
}
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
// See Patches.ts for additional errors
]
: []
export function die(error: number, ...args: any[]): never {
if (process.env.NODE_ENV !== "production") {
const e = errors[error]
const msg = isFunction(e) ? e.apply(null, args as any) : e
throw new Error(`[Immer] ${msg}`)
}
throw new Error(
`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
)
}
View on GitHub (pinned to d2c158f5ba)
Solutions
- Reproduce the same input under NODE_ENV=development (or a non-production build) to obtain the full [Immer] message for that code number.
- Map the number to its message using the dev errors table (src/utils/errors.ts:3-38; codes >= 16 live in the patches plugin block at src/plugins/patches.ts:36-48 with errorOffset 16).
- Apply the fix the dev message prescribes - the root cause is identical to the dev-mode error.
- Confirm your bundler replaces process.env.NODE_ENV correctly at build time so you do not ship a mixed or undefined state.
Example fix
// before: opaque error in a production bundle // -> [Immer] minified error nr: 1. Full error at: https://bit.ly/3cXEKWf // after: reproduce locally with a dev build to see the real message // NODE_ENV=development <run your app/tests> // -> [Immer] produce can only be called on things that are draftable: ...
Defensive patterns
Strategy: try-catch
Try / catch
// In production the message is opaque, so capture and log the code number,
// then reproduce the same input under NODE_ENV=development for the full text.
try {
nextState = produce(state, draft => {
/* recipe */
})
} catch (err) {
if (err instanceof Error && err.message.includes("[Immer] minified error nr:")) {
const nr = err.message.match(/nr:\s*(\d+)/)?.[1]
logger.error("Immer production error", {code: nr, input: state})
// map `nr` against src/utils/errors.ts (0-15) or patches errorOffset (16+)
}
throw err
} Prevention
- Reproduce any production Immer error under NODE_ENV=development to recover the full message before fixing.
- Map the numeric code to its text using src/utils/errors.ts:3-38 (codes 0-15) and src/plugins/patches.ts:36-48 (codes 16-19, errorOffset 16).
- Verify your bundler statically replaces process.env.NODE_ENV so dev error code is never shipped and prod builds strip the message table cleanly.
- Run the same isDraftable/isDraft pre-checks from the dev-mode strategy during development so the misuse never reaches production.
- Add a try/catch around produce()/applyPatches() at trust boundaries to log the code and input for post-deploy triage.
When it happens
Trigger: Identical conditions to the dev-mode die - any die(n) call - but encountered inside a production bundle (webpack/esbuild/rollup build with NODE_ENV=production, or a published/minified dependency). Execution still halts with a thrown Error; you simply lose the human-readable message and receive only the number.
Common situations: Errors that surface only in staging or production; a dependency whose build set NODE_ENV=production, stripping the message table; difficulty mapping the bare number to a root cause without the dev build; a bundler that left process.env.NODE_ENV undefined, producing inconsistent error output.
Related errors
AI-assisted analysis of immerjs/immer@d2c158f5ba (2026-08-13).
Data as JSON: /api/errors/90f886e1d695ffe9.
Report an issue: GitHub.