Alex
Alex

Reputation: 91

React Native Error: Unable to resolve module `./index` in node_modules/react-native

I am creating fresh react-native app:

npm install -g react-native-cli
react-native init FirstProject
cd FirstProject
react-native run-android

I see the following error message:

'Error: Unable to resolve module ./index from /home/alex/code/test2/FirstProject/node_modules/react-native/.'

By the way, file index.js was created at my project folder (/home/alex/code/test2/FirstProject/index.js)

This is the screenshot:

Upvotes: 3

Views: 10169

Answers (8)

Rushikesh
Rushikesh

Reputation: 86

I have same issue as you have TRY to install npm install or yarn install .Try to run both in your project folder by terminal of your code editor. It happen because of package only.if you don't upgrade your package it will show error. if you run npm install or yarn install it will install all package by default which are missing or which are not upgrade. if your are then also getting same error try to run npm install node oryarn install nodenode package might have issue. then also it is issue then there might another problem.

There is another way you can download simple app code from expo website or React native try to build your project in it.

Upvotes: 0

atmaram
atmaram

Reputation: 500

Just in case if anyone still have this issue, I have resolved it by resolving all possible extensions the app can support. In my case the modules and components were having .jsx where App is having .js.

Finally got my issue through by updating file - metro.config.js

resolver: {
    /* resolver options */
   sourceExts: ['jsx','js', 'ts', 'tsx', 'native', 'json'] //add here 
  },

Upvotes: 2

Sushant Patil
Sushant Patil

Reputation: 61

I resolved this issue by downgrading react native version to 0.58.6

This issue is because of new version of react native.(0.59.*)

Step 1: Delete node modules folder and package-lock.json file

Step 2: Change react-native version in package.json dependencies to 0.58.6

Step 3: run npm install on project root directory in command prompt

Step 4: run command react-native run-android

Done!

Upvotes: 2

Alex
Alex

Reputation: 91

I finally resolved the issue by downgrading to the previous version of react-native:

react-native init FirstProject --version 0.58.6

It seems that this issue is related only to the latest react-native, version 59. Previous version of react works.

Thank you everyone !

Upvotes: 1

Hadi Mir
Hadi Mir

Reputation: 5123

I had the same issue and I resolved it by installing the lower version of React.

Follow the below steps

  1. Delete the node_moduled folder by typing rm -rf node_modules/ in the terminal

  2. Delete the IOS and Android folders as well

  3. Edit the package.json and keep the dependencies and devDependencies as follows (Do not change your other setting in this file)

"dependencies": {
  "react": "16.6.3",
  "react-native": "0.58.5",
  //other dependencies 
},
"devDependencies": {
  "babel-core": "^7.0.0-bridge.0",
  "babel-jest": "24.1.0",
  "jest": "24.1.0",
  "metro-react-native-babel-preset": "0.52.0",
  "react-test-renderer": "16.6.3"
},

  1. Run yarn or npm install this will add node_modules again in your project
  2. Rum react-native upgrade to add Android and ios folder in your project

Best of luck

Upvotes: 2

Ukor
Ukor

Reputation: 331

I was having this same issue and these steps worked from me. This is more like a quick fix:

  • Downgrade the version of react and react-native from 0.59.1 to

"react": "16.8.3", "react-native": "0.59.0",

  • run npm install then react-native upgrade --legacy ,
  • Replace the android/app/build.gradle by pressing y
  • Rebuild you project react-native start -- --reset-cache
  • Run react-native run-android

Source 1
Source 2

Upvotes: 1

Pradnya Choudhari
Pradnya Choudhari

Reputation: 394

clean and install like below :

delete node_modules and run

 npm install
    npm link
    react-native run-android

Hope this works....

Upvotes: 0

Nehhal Kalnad
Nehhal Kalnad

Reputation: 111

I don't know the cause bro, Downgrade you react-native version to 0.58.5 (this worked for me)

react-native start -- --reset-cache

execute above command.

then do

react-native run-android

for more info refer this discussion

Upvotes: 7

Related Questions