immerjs / immer

Create the next immutable state by mutating the current one
https://immerjs.github.io/immer/
MIT License
27.79k stars 852 forks source link

React Native compilation problem #938

Closed Nadrenfox closed 2 years ago

Nadrenfox commented 2 years ago

Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 error While trying to resolve moduleimmerfrom fileC:\Users\nadre\Documents\Proyectos\ocho-react\node_modules\@reduxjs\toolkit\dist\redux-toolkit.cjs.production.min.js, the packageC:\Users\nadre\Documents\Proyectos\ocho-react\node_modules\@reduxjs\toolkit\node_modules\immer\package.jsonwas successfully found. However, this package itself specifies amainmodule 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:

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

hirbod commented 2 years ago

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: https://github.com/immerjs/immer/commit/b2db62b75bcf172266493ffea15edd7125663cb7#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R18

francois-codes commented 2 years ago

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

HarshitMadhav commented 2 years ago

+1 facing this same issue

826505523 commented 2 years ago

+2 facing this same issue

HarshitMadhav commented 2 years ago

https://github.com/immerjs/immer/pull/939 This issue has been fixed here

hirbod commented 2 years ago

I can confirm that the fix is working

francois-codes commented 2 years ago

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

HarshitMadhav commented 2 years ago

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

Nadrenfox commented 2 years ago

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