Error: Unable to resolve module `./index` from `node_modulesreact-nativescripts/ 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_modulesreact-nativescripts/. : The module ./index could not be found from node_modulesreact-nativescripts/. Indeed, none of these files exist.

Permanent Solution for Error: Unable to resolve module ./index from `node_modulesreact-nativescripts/:

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
reactnative runandroid command. You’ll see the magic your project will smoothly run without any error in emulator or real device.