Skip to content
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

import and call enableMapSet() error happens even after enableMapSet() is called. #1022

Closed
3 tasks done
github0013 opened this issue Mar 13, 2023 · 5 comments
Closed
3 tasks done

Comments

@github0013
Copy link

github0013 commented Mar 13, 2023

To Reproduce

Steps to reproduce the behavior:

https://codesandbox.io/p/sandbox/thirsty-dan-4e3o9r

  1. Open and wait, and you will see the error.
  2. Notice enableMapSet() in the code, but the error says

The plugin for 'MapSet' has not been loaded into Immer. To enable the plugin, import and call enableMapSet() when initializing your application.

Change the version to 9.0.12, then restart. Now the error is gone.

Observed behavior

A description of what behavior you observed and why you consider it faulty.

  • The version on the codesandbox is immer@9.0.19, but this error doesn't happen if it was immer@9.0.12.
  • This happens under nextjs projects. If the same code is run under a regular react app, things work without an error.

Expected behavior

A clear and concise description of what you expected to happen instead.

  • immer@9.0.13 - 9.0.19 shouldn't not show the error.

Environment

We only accept bug reports against the latest Immer version.

  • Immer version:
  • I filed this report against the latest version of Immer
  • Occurs with setUseProxies(true)
  • Occurs with setUseProxies(false) (ES5 only)
@mweststrate
Copy link
Collaborator

Typically one of two things is happening here:

  1. enableMapSet is called too late (it's generally hard to control that in JS, as module loading order is not always what you'd expect it to be
  2. there are two different versions of Immer in your dependency tree, and enableMapSet is imported from the different one as that is running the produce later. yarn why can be a grat help for that (there is probably an NPM equivalent)

@github0013
Copy link
Author

  1. so .. if I change the immer version, the error doesn't happen. Is it still an external problem?

Change the version to 9.0.12, then restart. Now the error is gone.

  1. I am reproducing the same error on codesandbox, so I don't think there are 2 different versions of immer.

@mweststrate
Copy link
Collaborator

I don't know how to test it in your sandbox, but it seems you have both xstate/immer and immer as dependencies, so enableMapSet is probably called on the wrong one, and I guess you don't need to install immer manually, or make sure to dedupe it.

@github0013
Copy link
Author

I guess you don't need to install immer manually,

So I removed immer, then I get this.

./node_modules/@xstate/immer/lib/index.js:5:0
Module not found: Can't resolve 'immer'

And I don't see enableMapSet is used in @xstate/immer. Again, this error doesn't happen under the same code if I downgrade immer version to 9.0.12.

@mweststrate
Copy link
Collaborator

mweststrate commented Mar 22, 2023

I just checked the @xstate/immer sources, they correctly set up immer as peer dependency, so it indeed needs to be included, and enableMapSet should hence affect it correctly.

So I think this issue is specifically caused by Next.js. I don't know how Next.js works, what is bundled on server vs client, or whether it brings an own internal 9.0.12 Immer version somewhere. So I think you can best raise this one with the Next.js community.

Edit: or you can ask @xstate/immer folks to enable MapSet by default, that'd fix the issue as well I suspect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants