enableMapSet() not working with xstate/immer + esbuild bundle
ShooTeX opened this issue Β· comments
πββ Question
I'm getting the following error message:
Error: [Immer] The plugin for 'MapSet' has not been loaded into Immer. To enable the plugin, import and call `enableMapSet()` when initializing your application.
at die (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/immer@9.0.21/node_modules/immer/src/utils/errors.ts:53:9)
at getPlugin (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/immer@9.0.21/node_modules/immer/src/utils/plugins.ts:52:3)
at createProxy (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/immer@9.0.21/node_modules/immer/src/core/immerClass.ts:231:5)
at Object.get2 (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/immer@9.0.21/node_modules/immer/src/core/proxy.ts:117:40)
at <anonymous> (/Users/stx/dev/esbuild-immer/src/index.ts:16:33)
at recipe (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/@xstate+immer@0.3.2_immer@9.0.21+xstate@4.37.1/node_modules/@xstate/immer/lib/index.js:8:77)
at Immer2.produce (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/immer@9.0.21/node_modules/immer/src/core/immerClass.ts:94:14)
at <anonymous> (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/@xstate+immer@0.3.2_immer@9.0.21+xstate@4.37.1/node_modules/@xstate/immer/lib/index.js:8:28)
at <anonymous> (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/xstate@4.37.1/node_modules/xstate/lib/utils.js:415:23)
at Array.reduce (<anonymous>)
This error only occurs after it is bundled and minified by esbuild, when using immer
with @xstate/immer
. Am I doing something wrong, is there anything I can do so I can bundle it?
could be related to #1022
Link to repro
https://github.com/ShooTeX/esbuild-immer
- clone
- pnpm start
Environment
We only accept questions against the latest Immer version.
- Immer version:
- Occurs with
setUseProxies(true)
- Occurs with
setUseProxies(false)
(ES5 only)
Code wise everything looks correct. Could you check if Immer ends up twice in your bundle, or that the enableMapSet()
is accidentally optimised away? (disabling minification simplifies checking that probably, if the error still occurs without minification)
it doesn't look like there are multiple instances of immer, but I don't see enableMapSet()
being called in the bundle, but I could be wrong. I'm not an expert in bundlers, do you have an idea why it could have been optimised away?
Edit: It looks like enableMapSet() is also being called
I updated the repo with a non-minified build in the dist directory
Can you share the stacktrace of the exception?
It might be that it is interpreteding
[https://github.com/immerjs/immer/blob/main/package.json#L18
](https://github.com/immerjs/immer/blob/main/package.json#L18%60) wrong, and applying it to the whole package rather than the pure functions. If you toggle that line in your local node_modules and rebuild again, does it fix the issue?
Doesn't look like it changed anything
Can you share the stacktrace of the exception?
Error: [Immer] The plugin for 'MapSet' has not been loaded into Immer. To enable the plugin, import and call `enableMapSet()` when initializing your application.
at die (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/immer@9.0.21/node_modules/immer/src/utils/errors.ts:53:9)
at getPlugin (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/immer@9.0.21/node_modules/immer/src/utils/plugins.ts:52:3)
at createProxy (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/immer@9.0.21/node_modules/immer/src/core/immerClass.ts:231:5)
at Object.get2 (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/immer@9.0.21/node_modules/immer/src/core/proxy.ts:117:40)
at <anonymous> (/Users/stx/dev/esbuild-immer/src/index.ts:16:33)
at recipe (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/@xstate+immer@0.3.2_immer@9.0.21+xstate@4.37.1/node_modules/@xstate/immer/lib/index.js:8:77)
at Immer2.produce (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/immer@9.0.21/node_modules/immer/src/core/immerClass.ts:94:14)
at <anonymous> (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/@xstate+immer@0.3.2_immer@9.0.21+xstate@4.37.1/node_modules/@xstate/immer/lib/index.js:8:28)
at <anonymous> (/Users/stx/dev/esbuild-immer/node_modules/.pnpm/xstate@4.37.1/node_modules/xstate/lib/utils.js:415:23)
at Array.reduce (<anonymous>)
Also have the same issue with Immer 10.x. Went back to latest 9.x for now
Using with
- vite 4.2.2
- @reduxjs/toolkit 1.9.5
- @redux-eggs/redux-toolkit 2.2.0
@Ethorsen note that Immer 10 will not work with RTK 1.9.5, as we still rely on the enableES5()
plugin in 1.9.x. The RTK 2.0 alphas have been updated to work with Immer 10.
Closing as Immer 10 was released.