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

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: #23908

Closed
moinulhuq opened this issue Mar 13, 2019 · 98 comments
Labels
Bug Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.

Comments

@moinulhuq
Copy link

🐛 Bug Report

I am getting this error when upgrade my react native.

It says

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:

To Reproduce

react-native run-android

Expected Behavior

Should run the App

Code Example

{
"name": "RedCrow",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"axios": "^0.18.0",
"leaflet": "^1.4.0",
"moment": "^2.24.0",
"native-base": "^2.12.1",
"node-pre-gyp": "^0.12.0",
"prop-types": "^15.7.2",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-leaflet": "^2.2.1",
"react-native": "^0.59.0",
"react-native-camera": "^1.13.1",
"react-native-fs": "^2.13.3",
"react-native-gesture-handler": "^1.1.0",
"react-native-image-crop-picker": "^0.22.0",
"react-native-image-picker": "^0.28.0",
"react-native-modal": "^7.0.2",
"react-native-vector-icons": "^6.4.1",
"react-native-video": "^4.4.0",
"react-native-webview": "^5.3.0",
"react-native-webview-leaflet": "^4.1.22",
"react-navigation": "^3.3.2",
"react-navigation-props-mapper": "^0.3.0",
"react-redux": "^6.0.1",
"realm": "^2.25.0",
"redux": "^4.0.1",
"redux-form": "^8.1.0",
"rn-fetch-blob": "^0.10.15",
"util": "*"
},
"devDependencies": {
"babel-jest": "^24.5.0",
"jest": "^24.5.0",
"metro-react-native-babel-preset": "0.51.1",
"react-test-renderer": "16.6.3"
},
"jest": {
"preset": "react-native"
}
}

Environment

"react": "^16.8.4",
"react-native": "^0.59.0",

@react-native-bot react-native-bot added the Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used. label Mar 13, 2019
@react-native-bot
Copy link
Collaborator

Can you run react-native info and edit your issue to include these results under the Environment section?

If you believe this information is irrelevant to the reported issue, you may write `[skip envinfo]` alongside an explanation in your Environment: section.

@haztares
Copy link

@moinulhuq! Yeah I have been the same :(.

@chenxin0916
Copy link

same issues

@dancomanlive
Copy link

dancomanlive commented Mar 14, 2019

Got the same issue initially with yarn start but after running react-native start -- --reset-cache got the following error message:
Screen Shot 2019-03-14 at 15 47 39

*I am inside the right folder btw

@chenxin0916
Copy link

I restore my project and use new new method to upgrade:
1.change the version of react and react-native
"react": "16.8.3",
"react-native": "0.59.0",
2 .run npm install then react-native upgrade --legacy ,that will change your some files (decide whether to cover as needed)
3. need upgrade you gradle version(>4.10.1) and android sdk(>=28)
4.rebuild you project and upgrade success without this error

@davidvorona
Copy link

NOTE: One difference between my error and OP's is I'm unable to resolve the module ./index from /node_modules/react-native/. (as opposed to /node_modules/react-native/scripts/.).

I'll second this. After upgrading from 0.58.6 to 0.59.1 I get this error on both iOS and Android. Here is my react-native info output:

info 
  React Native Environment Info:
    System:
      OS: Linux 4.18 Ubuntu 18.10 (Cosmic Cuttlefish)
      CPU: (16) x64 AMD Ryzen 7 2700X Eight-Core Processor
      Memory: 389.57 MB / 15.68 GB
      Shell: 5.5.1 - /usr/bin/zsh
    Binaries:
      Node: 11.10.1 - /usr/bin/node
      Yarn: 1.13.0 - /usr/bin/yarn
      npm: 6.7.0 - /usr/bin/npm
    SDKs:
      Android SDK:
        API Levels: 23, 24, 25, 26, 27, 28
        Build Tools: 28.0.2, 28.0.3
        System Images: android-28 | Google APIs Intel x86 Atom
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5314842
    npmPackages:
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.1 => 0.59.1 
    npmGlobalPackages:
      react-native-cli: 2.0.1

I can't imagine it's an issue with specific Android/iOS config and build files since I get the same error across platforms, but I can provide them if necessary. My gradle version is ~4.10.2 and Android SDK version is ~28.

I've taken the usual steps when encountering a problem while updating RN:

  • deleting React, metro, yarn, and haste caches in $TMPDIR
  • deleting node_modules
  • react-native start -- --reset-cache
  • cleaning build folders for both iOS and Android

No luck so far, any help would be appreciated.

@tzurae
Copy link

tzurae commented Mar 15, 2019

same issue + 1

@elhachimi
Copy link

elhachimi commented Mar 15, 2019

After creating a new project using React-native 0.59 , i copied metro.config.js, .flowconfig and babel.config.js to the old project and it started to work again

@viuts
Copy link

viuts commented Mar 15, 2019

the issue only happens when I press Play button and build using xcode, but when I run npm start -- --reset-cache it will works

@silenjs
Copy link

silenjs commented Mar 15, 2019

Moved iOS build cache directory from ~/.rncache to ~/Library/Caches/com.facebook.ReactNativeBuild

Could be because the cache directory already changed
refer to @chenxin0916 ,Handing conflicts
then
run react-native start --cache-reset to clear the bundle cache first
now you can run-ios/android

@soetedja
Copy link

soetedja commented Mar 16, 2019

run
react-native start -- --reset-cache
then
react-native run-android in separate command line

works fine for me, maybe just for a temporary solution.

there is another solution from @nazreinkaram by updating launchPackager.bat, no need to open two cmd line. thanks

@nirajhi
Copy link

nirajhi commented Mar 17, 2019

NOTE: One difference between my error and OP's is I'm unable to resolve the module ./index from /node_modules/react-native/. (as opposed to /node_modules/react-native/scripts/.).

I'll second this. After upgrading from 0.58.6 to 0.59.1 I get this error on both iOS and Android. Here is my react-native info output:

info 
  React Native Environment Info:
    System:
      OS: Linux 4.18 Ubuntu 18.10 (Cosmic Cuttlefish)
      CPU: (16) x64 AMD Ryzen 7 2700X Eight-Core Processor
      Memory: 389.57 MB / 15.68 GB
      Shell: 5.5.1 - /usr/bin/zsh
    Binaries:
      Node: 11.10.1 - /usr/bin/node
      Yarn: 1.13.0 - /usr/bin/yarn
      npm: 6.7.0 - /usr/bin/npm
    SDKs:
      Android SDK:
        API Levels: 23, 24, 25, 26, 27, 28
        Build Tools: 28.0.2, 28.0.3
        System Images: android-28 | Google APIs Intel x86 Atom
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5314842
    npmPackages:
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.1 => 0.59.1 
    npmGlobalPackages:
      react-native-cli: 2.0.1

I can't imagine it's an issue with specific Android/iOS config and build files since I get the same error across platforms, but I can provide them if necessary. My gradle version is ~4.10.2 and Android SDK version is ~28.

I've taken the usual steps when encountering a problem while updating RN:

  • deleting React, metro, yarn, and haste caches in $TMPDIR
  • deleting node_modules
  • react-native start -- --reset-cache
  • cleaning build folders for both iOS and Android

No luck so far, any help would be appreciated.

I have the same issue. Have you found the solution?

@haztares
Copy link

After creating a new project using React-native 0.59 , i copied metro.config.js, .flowconfig and babel.config.js to the old project and it started to work again

Thanks you. I tried and success :). Everyone can try

@alainib
Copy link

alainib commented Mar 18, 2019

I get the same issu on IOS,
after cache clear i get app stuck on "downloading javascript bundle 100%" and black screen below,
no error on metro console, when debug mode is on.

if i remove debug mode the app start. but need debug. any idea ? thanks

@sarazeaiter1
Copy link

After creating a new project using React-native 0.59 , i copied metro.config.js, .flowconfig and babel.config.js to the old project and it started to work again

I just copied metro.config.js and it works perfectly. Thanks a lot

@alainib
Copy link

alainib commented Mar 18, 2019

can someone past the content and path of the metro.config.js file please ?

I have one in

  • node_modules\metro\src\integration_tests
  • node_modules\react-native\template

@kelset
Copy link
Collaborator

kelset commented Mar 18, 2019

Hello everyone - this issue seems to be related to your experience upgrading between versions. We know this has been a long lasting pain for the community so starting v0.59 we have introduced a new flow via the new CLI.

But, to upgrade to that version, you still need some potentially manual steps - we suggest you use the rn-diff-repo to accomplish this.

Given that this is not strictly a bug with the library itself I'll close this, but if someone can create a repro that has this issue with a freshly created react-native init project we can reopen it and discuss it further 🤗

@alainib you can use the one in https://github.com/facebook/react-native/tree/0.59-stable/template

@kelset kelset closed this as completed Mar 18, 2019
@nabylb
Copy link

nabylb commented Mar 19, 2019

Thanks @kelset! It took me a while to fix this. Like @saraztr and others said, copying metro.config.js from a 0.59 new project fixes the issue.

@alainib , here's the metro.config.js content:

/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/

module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
};

@VivekkChudasama
Copy link

same issues

Error: Unable to resolve module ./index from \node_modules\react-native\scripts/.: The module ./indexcould not be found from\node_modules\react-native\scripts/.`

React Native Environment Info:
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i3-3110M CPU @ 2.40GHz
Memory: 569.59 MB / 3.89 GB
Binaries:
Yarn: 1.12.3 - C:\Users\Vivek\AppData\Roaming\npm\yarn.CMD
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.3.0.0 AI-182.5107.16.33.5314842

Environment :
"react": "16.8.3",
"react-moment": "^0.8.4"

Screenshot_2019-03-19-15-10-02-231_com usersmanager

@alainib
Copy link

alainib commented Mar 19, 2019

@VivekkChudasama try to

  • npm cache clean --force
  • install metro in package.json devDependencies
  • put the metro.config.js posted before
  • remove node_modules folder and npm install again
  • gradlew clean on android (cd android ; ./gradlew clean ; cd .. )
  • remove pods folder on ios and install again (cd ios ; pod install ; cd .. )

@ahmad6242
Copy link

@VivekkChudasama WHat do you mean by put the metro.config.js posted before?

@nabylb
Copy link

nabylb commented Mar 21, 2019

@ahmad6242, create a new file in your RN project root folder named metro.config.js with the content below:

/**

module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
};

@shreyasnisal
Copy link

I tried cleaning the cache, removing the node_modules directory and reinstalling using npm install, with no luck. I already had a metro.config.js file in the project root directory. I am using react v16.8.5 and react-native v0.59.1

@alainib
Copy link

alainib commented Mar 23, 2019

I tried cleaning the cache, removing the node_modules directory and reinstalling using npm install, with no luck. I already had a metro.config.js file in the project root directory. I am using react v16.8.5 and react-native v0.59.1

did you have last metro in dev dependancies ?

@sylvainbaronnet
Copy link

sylvainbaronnet commented Mar 23, 2019

Same issue, I even tried a new app from scratch without changing anything and I got the same error...

  React Native Environment Info:
    System:
      OS: macOS 10.14.1
      CPU: (12) x64 Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
      Memory: 107.03 MB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 11.12.0 - /usr/local/bin/node
      Yarn: 1.15.2 - /usr/local/bin/yarn
      npm: 6.7.0 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
    IDEs:
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3
      react-native: 0.59.1 => 0.59.1
    npmGlobalPackages:
      react-native-cli: 2.0.1

@elvi5tim
Copy link

And i have same issue, with new app:
react-native init TestProject --template typescript
@soetedja solution helped me

@consule
Copy link

consule commented Mar 29, 2019

react-native info

info
React Native Environment Info:
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i3-5005U CPU @ 2.00GHz
Memory: 608.47 MB / 3.90 GB
Binaries:
Yarn: 1.12.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.7.0 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.1.0.0 AI-173.4720617

@bicibg
Copy link

bicibg commented Mar 31, 2019

i can confirm this works and fixes the issue

run
react-native start -- --reset-cache
then
react-native run-android in separate command line

@sm2017
Copy link
Contributor

sm2017 commented Apr 7, 2019

I have same issue , When I upgrade to 0.59.2 , I must always put --reset-cache to start package

@awan2008
Copy link

Updated status as of now, Using the newest version 0.59, I am able to fire up new vanillla project without error.

@alainib
Copy link

alainib commented Apr 25, 2019

I got this problem few days ago. today after erasing node_modules it get back

I have metro.config.js as posted above

i tried :

  • in react-native\scripts\launchPackager.bat

    // delete this line
    // node "%~dp0..\cli.js" start
    // Add this line
    node "%~dp0..\cli.js" start --projectRoot ../../../

  • Or in \node_modules@react-native-community\cli\build\commands\runAndroid\runAndroid.js

    const procConfig = {
    // delete this line
    // cwd: scriptsDir
    // add this line
    cwd: process.cwd()
    };

I give me this error now :

error: bundling failed: Error: Unable to resolve module `./utils/batch` 
from `...node_modules\react-redux\lib\index.js`:
 The module `./utils/batch` could not be found from `...node_modules\react-redux\lib\index.js`.
 Indeed, none of these files exist:

"react-native": "0.59.2"
"react": "16.8.6"
"react-redux" : "6.0.1"

@sunnylqm
Copy link
Contributor

@alainib update to latest version

@alainib
Copy link

alainib commented Apr 26, 2019

@alainib update to latest version

i tried ( failled completly )

"react": "16.8.6", "react-native": "0.59.5", "react-redux" : "7.0.2"

https://i.ibb.co/3dHLtzp/Screenshot-2019-04-26-09-48-24.png

@alainib
Copy link

alainib commented Apr 26, 2019

it finally worked thank you

  • delete node_modules folder

  • package.json : "react": "16.8.3", "react-native": "0.59.2", "react-redux": "6.0.1"

  • npm install

  • live the node_modules\react-native\scripts\launchPackager.bat as it with node "%~dp0..\cli.js" start

  • change @react-native-community\cli\build\commands\runAndroid\runAndroid.js :

    const procConfig = { cwd: process.cwd() }

  • npm cache clean --force

  • npm start --clear-cache

  • react-native start --reset-cache
    AND THIS STEP I DIDNT DONE BEFORE

  • delete C:\Users\YOURUSERNAME\AppData\Local\Temp\metro-cache

@NomanGul
Copy link

Thanks, @Souradeep-16

Just Run With 'react-native start' In a Command line & run 'react-native run-android' in another new command line .Then It will Work Fine.
@this error is happening for directory problem in nodemodules/react-native/script....

@arkhamsushant
Copy link

Metro server instance here is started by runAndroid.js if you ask for react-native run-android
I can help you with android only, I am giving you fix on windows, if you are on Linux then I am sure you definitely know how to apply these fixes on your machine.
Problem is with Working Directory, Metro instance is launched with wrong working directory and no project root is passed in launchPackager
Threre are two fixes for this issue, apply only one of the below

Update node_modules\react-native\scripts\launchPackager.bat file.

@echo off
title Metro Bundler
call .packager.bat

// delete this line
node "%~dp0..\cli.js" start 

Add this line
node "%~dp0..\cli.js" start --projectRoot ../../../ 

pause
exit

We are giving project root path to Metro instance here,

Or in \node_modules\@react-native-community\cli\build\commands\runAndroid\runAndroid.js edit this,

const procConfig = {

    // delete this line    
    cwd: scriptsDir

    // add this line
    cwd: process.cwd()
};

We launched Metro launcher with working directory to our project root

The only way to run vanilla app is to update above workaround from our savior @nazreinkaram . Or, initiate using EXPO.

This worked for me even after upgrading to 0.59.2. Seems like a big issue with RN still

This worked for me for 0.59.0. However, is this fixed in a higher version of RN.

@basha777
Copy link

basha777 commented Jun 26, 2019

I tried upgrading to 0.59.0 faced the same issue, later upgraded to 0.59.9 solved this issue.

@eric-cc
Copy link

eric-cc commented Jul 2, 2019

Using latest 0.59.10 - fresh project - moving App.js, app.json and index.js into a src folder. Setting projectRoot as src is ignored.

@luky1984
Copy link

luky1984 commented Jul 12, 2019

it looks it is permanently broken, only thing that temproray works is this #23908 (comment)

i dont know how the error happened, i had some errors with iOS pods first, then i ran yarn install and also npm install (maybe mistake to run both but probably its not the reason), i even deleted problematic folder in ios pods, didnt help, then i ran lot of commands like rm -rf node_modules, npm install etc nothing helped then the error as stated by the thread starter happened. so something somewhere is still broken.

EDIT: updating

"react-native": "0.59.1",

to

"react-native": "0.59.10",

seems to fix the error.

@TCarmine
Copy link

Those steps except the last 2 fix the issue that arise after I installed exios lib.

  • radlew clean on android (cd android ; ./gradlew clean ; cd .. )

  • remove pods folder on ios and install again (cd ios ; pod install ; cd .. )

@Yingi
Copy link

Yingi commented Jul 18, 2019

I think from RN version 0.59.0 you have to manually start the server
that is

run react-native start

And then open another terminal and then run

react-native run-android

previous version automatically starts the development server. But I think there is a change from RN 0.59.0 upwards.

The above was what worked for me

@msqar
Copy link

msqar commented Jul 24, 2019

same issues

Error: Unable to resolve module ./index from \node_modules\react-native\scripts/.: The module ./indexcould not be found from\node_modules\react-native\scripts/.`

React Native Environment Info:
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i3-3110M CPU @ 2.40GHz
Memory: 569.59 MB / 3.89 GB
Binaries:
Yarn: 1.12.3 - C:\Users\Vivek\AppData\Roaming\npm\yarn.CMD
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.3.0.0 AI-182.5107.16.33.5314842

Environment :
"react": "16.8.3",
"react-moment": "^0.8.4"

Screenshot_2019-03-19-15-10-02-231_com usersmanager

Hey, were you able to solve it? I'm under the same issue :S

@FullstackJack
Copy link

FullstackJack commented Aug 2, 2019

It's a liar. That file does indeed exist!

Since my React Native test runner is nested inside an examples directory of the main module repo. I have a .watchmanconfig with the following.

{
    "ignore_dirs": [
        ".git",
        "node_modules",
        "examples"
    ]
}

If you follow the recommendation to watchman watch-del and watchman watch-project, you'll pickup the .watchmanconfig which stops watching examples, etc. If you watch your nested project to run again, just don't do the watch-project command after watch-deling.

I don't know if this causes other problems, but this is how I got my project working again:

watchman watch-del /Users/username/code/project/react-native-video/examples/MyExampleProject and that's it! Don't watchman watch-project.

Update:

Actually I'm back to square one. It broke again when I ran wml to handle the puedo symlinking.

@danielsotopino
Copy link

I updated to this

"metro-react-native-babel-preset": "0.54.1"

And started workinng again.

@FunkyLambda
Copy link

FunkyLambda commented Aug 22, 2019

Just Run With 'react-native start' In a Command line & run 'react-native run-android' in a another new command line .Then It will Work Fine.
@this error is happening for directory problem in nodemodules/react-native/script....

I think from RN version 0.59.0 you have to manually start the server
that is

run react-native start

And then open another terminal and then run

react-native run-android

previous version automatically starts the development server. But I think there is a change from RN 0.59.0 upwards.

The above was what worked for me

So with the release of 0.59, the debugging process of an RN app is even more painful than it already was?

What a load of crap this development platform is. I can't believe it even exists, let alone the morons who choose it for their projects. I have no choice, I'm stuck with existing projects that I have to support.

Compare it with Xamarin: To debug in either platform, you press the Play button. That's it.

@kamiranoff
Copy link

kamiranoff commented Sep 17, 2019

For some reason, none of these worked for me.
At the brink of insanity, I just created an index.android.js file at the root of my folder and it started to work again

Hoping to find a better solution...

@BriantOliveira
Copy link

I got the same issue when I updated my app react-native version. I deleted the node_modules file and ran the npm install command again to reinstall all the modules and the error went away.

@oojikoo
Copy link

oojikoo commented Jan 28, 2020

For some reason, none of these worked for me.
At the brink of insanity, I just created an index.android.js file at the root of my folder and it started to work again

Hoping to find a better solution...

This worked for me.

@marcosadsj
Copy link

I had put my hook useDispatch outside of my function component... maybe it can help someone

@ryoid
Copy link

ryoid commented Mar 2, 2020

For some reason, none of these worked for me.
At the brink of insanity, I just created an index.android.js file at the root of my folder and it started to work again

Hoping to find a better solution...

Was only getting this issue on android, I had changed my entry file in app/build.gradle suspected that might be it. Added an index.android.js to my root and imported my actual files (./src) and it works.

System:
OS: Windows 10 10.0.18363
CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
Memory: 16.09 GB / 31.95 GB
Binaries:
Node: 12.16.1 - C:\Users\ryoid\scoop\apps\nvm\current\nodejs\nodejs\node.EXE
Yarn: 1.22.0 - C:\Users\ryoid\scoop\apps\nvm\current\nodejs\nodejs\yarn.CMD
npm: 6.13.4 - C:\Users\ryoid\scoop\apps\nvm\current\nodejs\nodejs\npm.CMD
SDKs:
Android SDK:
API Levels: 28, 29
Build Tools: 28.0.3, 29.0.2
System Images: android-25 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.5 => 0.61.5

@facebook facebook locked as resolved and limited conversation to collaborators Mar 18, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.
Projects
None yet
Development

No branches or pull requests