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

React Native compilation problem

Nadrenfox opened this issue · comments

Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 error While trying to resolve module immerfrom fileC:\Users\nadre\Documents\Proyectos\ocho-react\node_modules@reduxjs\toolkit\dist\redux-toolkit.cjs.production.min.js, the package C:\Users\nadre\Documents\Proyectos\ocho-react\node_modules@reduxjs\toolkit\node_modules\immer\package.jsonwas successfully found. However, this package itself specifies amain module field that could not be resolved (C:\Users\nadre\Documents\Proyectos\ocho-react\node_modules@reduxjs\toolkit\node_modules\immer\dist\immer.esm.mjs`. Indeed, none of these files exist:

  • C:\Users\nadre\Documents\Proyectos\ocho-react\node_modules@reduxjs\toolkit\node_modules\immer\dist\immer.esm.mjs(.native|.android.js|.native.js|.js|.android.json|.`
    I can't compile my code

I was trying to compile in react native redux tookit that uses immer and it seems is not working anymore for some reason.

I had the same problem, this is most likely related to the ESM changes that many packages start doing.
You need to change your metro config

// Learn more https://docs.expo.io/guides/customizing-metro
const {
  getDefaultConfig
} = require('expo/metro-config');
const path = require('path');

const config = getDefaultConfig(__dirname);

// Monorepo
const projectRoot = __dirname;
const workspaceRoot = path.resolve(__dirname, '../..');

config.watchFolders = [workspaceRoot];
config.resolver.nodeModulesPath = [
  path.resolve(projectRoot, 'node_modules'),
  path.resolve(workspaceRoot, 'node_modules')
];

config.resolver.sourceExts.push('mjs'); // this is the required fix

module.exports = config;

Note that my metro config is based off Expo, if you're using bare RN you'll need to add mjs to your sourceExts.

I still think that immerjs should also support react-native ootb, there are many issues in this direction lately from many packages, like uSES, react-query, apollo. etc.

That's the line that caused the issues:
b2db62b#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R18

Is there a plan to do anything about this ?

we have a framework that uses reduxjs/toolkit as a dependency. With this, all our earlier versions are now breaking in new projects, unless people add a specific resolution for immer version, which is quite problematic

+1 facing this same issue

+2 facing this same issue

#939
This issue has been fixed here

I can confirm that the fix is working

yes, this can be closed, #939 was merged and is available in 9.0.14

I think we can close this issue as of now as it has been fixed.

Yup, closing it now, thank you all for help!