Home > other >  Immer error when using redux/toolkit with React-Native (iOS)
Immer error when using redux/toolkit with React-Native (iOS)

Time:05-12

I'm trying to use @redux/toolkit in my react-native app. However, when I run the iOS simulator I get the following error.

Metro has encountered an error: While trying to resolve module immer from file /path-node-modules/node_modules/@reduxjs/toolkit/dist/redux-toolkit.cjs.production.min.js, the package /path-node-modules//node_modules/immer/package.json was successfully found. However, this package itself specifies a main module field that could not be resolved (/path-node-modules/node_modules/immer/dist/immer.esm.mjs. Indeed, none of these files exist:

  • /path-node-modules/node_modules/immer/dist/immer.esm.mjs(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
  • /path-node-modules/node_modules/immer/dist/immer.esm.mjs/index(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)

I found a similar issue on immer's github repo that was resolved in 2019, but I'm still seeing this today (which is weird because I have all the latest packages).

I edited the node-modules path, because it starts from my root directory.

Any ideas on how to resolve this?

CodePudding user response:

Seems like adding mjs to the metro config did the trick.

const { getDefaultConfig } = require("expo/metro-config");

const defaultConfig = getDefaultConfig(__dirname);

defaultConfig.resolver.sourceExts = ['jsx', 'js', 'ts', 'tsx', 'mjs'];

module.exports = defaultConfig;

CodePudding user response:

I just installed version of 9.0.12 for Immer and it fixed! I guess there is issue in version of 9.0.13.

  • Related