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

React Native compilation problem #938

Closed
Nadrenfox opened this issue May 12, 2022 · 9 comments
Closed

React Native compilation problem #938

Nadrenfox opened this issue May 12, 2022 · 9 comments

Comments

@Nadrenfox
Copy link

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.

@hirbod
Copy link

hirbod commented May 12, 2022

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

@francois-codes
Copy link

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
Copy link

+1 facing this same issue

@826505523
Copy link

+2 facing this same issue

@HarshitMadhav
Copy link

#939
This issue has been fixed here

@hirbod
Copy link

hirbod commented May 12, 2022

I can confirm that the fix is working

@francois-codes
Copy link

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

@HarshitMadhav
Copy link

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

@Nadrenfox
Copy link
Author

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

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

5 participants