Error: Unable to resolve module `./index` from `\node_modules\react-native\scripts/ Solution

Since we all know react native has recently launched its newly more compatible 0.59.2 version with some basic changes. But after upgrading to new version or creating new react native project we all have faced a common error. The error is coming from the Metro server instance. When we run our react native project then it will launched with wrong working directory and no project root is passed in launchPackager.

Screenshot of Error:

Error Message:

Error: Unable to resolve module ./index from \node_modules\react-native\scripts/. : The module ./index could not be found from \node_modules\react-native\scripts/. Indeed, none of these files exist.

Permanent Solution for Error: Unable to resolve module ./index from `\node_modules\react-native\scripts/:

1. Goto Your_React_Native_Project -> node_modules -> react-native -> scripts -> launchPackager.bat . Open the launchPackager.bat file in Notepad or Notepad ++  editor.

2. Put below line of code in launchPackager.bat file.

Source code of launchPackager.bat file after making changes:

3. Now we need to give the project root path to metro instance object. So GoTo React_Native_Project -> node_modules -> @react-native-community -> cli -> build -> commands -> runAndroid.js . Open the runAndroid.js file in Notepad editor.

4. Find cwd: scriptsDir in const procConfig block.

5. Replace cwd: scriptsDir with cwd: process.cwd() code & save the file.

6. Now goto your project’s main root folder in command prompt or Terminal and execute react-native run-android command. You’ll see the magic your project will smoothly run without any error in emulator or real device.

19 Comments

  1. This does not solve the problem. Still having the same error. Only solution that is working is ‘npm start — –reset-cache’ , but this is not the permanent solution

  2. Thank you mate! Your solution fixed the error!

  3. Thank you I did and succeeded

  4. Thanks, solved my problem

  5. just worked for me… thanks 🙂

  6. this is work for me thanks
    React_Native_Project -> node_modules -> @react-native-community -> cli -> build -> commands -> runAndroid-> runAndroid.js on line 248

  7. Hi folks, I have tried with react native 0.59.3(latest) and it works fine and no need to made any changes in the launchPackager.bat file.

  8. Still not worked for me

  9. could not work for me.
    React_Native_Project -> node_modules -> @react-native-community -> cli -> build -> commands -> runAndroid->

    i do not have cli but have cli-platform-andriod. even if i tried on this in runAndriod i do not have runAndriod.js

  10. its still not working for me

Leave a Reply

Your email address will not be published. Required fields are marked *