Reputation: 91
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
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 node
node 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
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
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
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
Reputation: 5123
I had the same issue and I resolved it by installing the lower version of React.
Follow the below steps
Delete the node_moduled
folder by typing rm -rf node_modules/
in the terminal
Delete the IOS and Android folders as well
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"
},
yarn
or npm install
this will add node_modules
again in your projectreact-native upgrade
to add Android
and ios
folder in your projectBest of luck
Upvotes: 2
Reputation: 331
I was having this same issue and these steps worked from me. This is more like a quick fix:
0.59.1
to"react": "16.8.3",
"react-native": "0.59.0",
npm install
then react-native upgrade --legacy
,android/app/build.gradle
by pressing y
react-native start -- --reset-cache
react-native run-android
Upvotes: 1
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
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