React-native: Can't run a fresh new project (unable to resolve module ./index)

Created on 23 Mar 2019  ·  63Comments  ·  Source: facebook/react-native

🐛 Bug Report

I created a new project using "react-native init test" and run using "react-native run-android". The project was succesfully compiled but when it starts I got this error:

Screenshot_1553351834

Environment

info
React Native Environment Info:
System:
OS: Windows 7
CPU: (8) x64 Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz
Memory: 498.70 MB / 3.95 GB
Binaries:
npm: 6.1.0 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.3.0.0 AI-182.5107.16.33.5264788

Bug Android Windows Fixed Locked 📦Bundler

Most helpful comment

Temporary workaround for Windows users
Go to your PROJECT_FOLDER/node_modules/react-native/scripts
Open the file launchPackager.bat with your favorite text editor and add this line

cd "%~dp0..\..\..\"

as follows

@echo off
title Metro Bundler
call .packager.bat
cd "%~dp0..\..\..\"
node "%~dp0..\cli.js" start
pause
exit

Then run react-native run-android normally

All 63 comments

I had the same. Just create a new project with react-native init projectName --version [email protected]. The RN 0.59.1 ins't working since yesterday unfortunately.

Same problem here!
error 500a

System: Mint Tara
CPU: (8) x64 Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz
Memory: 16 GB
Android Studio 3.3.2
Build #AI-182.5107.16.33.5314842, built on February 15, 2019
JRE: 1.8.0_152-release-1248-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-46-generic

Same exact problem I am facing too. I just updated to 0.59.1 and this isn't working...
As a work around, I am running the metro builder in a separate tab, and then running react in a separate tab.

react-native start --reset-cache in one terminal and left it open
react-native run-android in another terminal

@Gerlison I am facing the same issue even with 0.58.6 version.

I'm facing the same issue. I had a project that I started with an older version of React Native (I don't recall which). After upgrading to the latest, I get the same error as reported in this issue when starting my app with react-native run-ios. When started this way, Metro Bundler reports the wrong folder--it seems to be tacking on an extra "/node_modules/react-native":
Looking for JS files in /my_project_path/node_modules/react-native

If I manually start the packager with react-native start, then it uses the correct folder and works fine.
Looking for JS files in /my_project_path

Also, any new project I create with react-native init has the same problem.

Here's the output of react-native info on my system:
React Native Environment Info:
System:
OS: macOS 10.14.3
CPU: (8) x64 Intel(R) Core(TM) i7-3820QM CPU @ 2.70GHz
Memory: 128.53 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
react-native: 0.59.1

make sure you open your android sim first before running react-native run-android. Its a bug that needs to be fixed.

FYI, not sure about Android, but that didn't make a difference on iOS. Even if I have the simulator open when running react-native run-ios, Metro still looks in the wrong folder for sources.

@jerryryle sorry about that. I didn't read the error message all the way through. I have 59.1 working for ios and android on a new repo here https://github.com/jeffreymendez1993/react-unity. Make sure you have you packager running and kill any old instances beforehand. Use react-native start --reset-cache

I have same proublem with 0.59.0 and 0.59.1 but not for .58.6 and others.

For 0.59.0 and 0.59.1, I must every time run this command:

react-native start --reset-cache in one terminal and left it open
react-native run-android in another terminal

So I prefer use 0.58.6 until next stable version.

yes, switch to older version and all should work smooth.

Same problem on 0.59.1 after hitting the play button in Xcode.

Confirming react-native start --reset-cache fixes this on macOS

I have the same problem on 0.59.1 after upgrading from 0.58.6.
Thanks from bahaedini's workaround.

I think we should stay in 0.58.6 until this problem has been resolved.

Hey all, thanks for the report. I'm looking into this now, have confirmed the same behaviour occurs for me locally - will report back when I have something more.

EDIT: Looks like this issue is only for the automatically launched packager as part of react-native run-android - if you run react-native start separately before run-android you should be good for now.

This has been fixed in https://github.com/facebook/react-native/commit/392b0845ce624de0632721c67d349455e5029715#diff-fe2ea122979e8bb9729dff893828ae61 and is pending a release.

I'll lock this issue but keep it open for visibility. Will close once a release has been published.

Thanks

Hey all, v0.59.2 has been published with this fix, please can you give it a try and let me know if it's ok now. Thanks

I can confirm that this solved the problem for me in iOS in both my existing application and a new application created with react-native init.

I couldn't use react-native upgrade since the diff doesn't seem to exist yet (error: "Failed to fetch diff for [email protected]. Maybe it's not released yet?"), so I used npm install --save react-native to upgrade my pre-existing project and npm install -g react-native to upgrade the global instance. Immediately after doing this, I ran react-native run-ios and the packager launched, looking for sources in the correct project folder. Same for a new project.

Thank you for fixing that so quickly.

@jerryryle thanks for confirming the fix is working. The diff will be there eventually, the release was only just published when I replied earlier 🙃

I'll go ahead and close this issue now. Thanks everyone.

Can anyone confirm for android? I'm still seeing the issue on new projects after installing .59.2...might just be me though...

Project created by V0.59.1.
Version number modification 0.59.2 is acceptable

@jerryryle thanks for confirming the fix is working. The diff will be there eventually, the release was only just published when I replied earlier 🙃

I'll go ahead and close this issue now. Thanks everyone.

it's not ok for android version. i've already upgrade to RN0.59.2 but still getting unable to resolve module './index...' =(

it's still not working on Android after upgrading it to RN0.59.2

The issue persists when running on Android

$ react-native info
info
  React Native Environment Info:
    System:
      OS: Windows 10
      CPU: (12) x64 Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
      Memory: 24.55 GB / 31.93 GB
    Binaries:
      Yarn: 1.15.2 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
      npm: 6.7.0 - C:\Program Files\nodejs\npm.CMD
    IDEs:
      Android Studio: Version  3.3.0.0 AI-182.5107.16.33.5314842

Create a new project on 0.59.2, still need to do 'react-native start --reset-cache' manually to kick it start up correctly.

Create a new project on 0.59.2, still need to do 'react-native start --reset-cache' manually to kick it start up correctly.

Okay, for now one must run react-native start --reset-cache in one terminal and then run react-native run-android in another terminal to run successfully, not running the Metro Bundler manually with --reset-cache no longer works (for android).

Will this issue be fixed going forward?

Same issue on my new project.
I got stuck on this command: react-native start --reset-cache

Re-opened as this issue still seems to be affecting Windows users - could someone confirm on Windows for me, please?

On windows Still not working, same error as before.

@Salakar I'm Windows user, I confirm this issue still exist.
I just test it again a minute ago.

Re-opened as this issue still seems to be affecting Windows users - could someone confirm on Windows for me, please?

i have same problem in windows too

Re-opened as this issue still seems to be affecting Windows users - could someone confirm on Windows for me, please?

Yes, I am also facing the same issue on Windows OS when running on physical Android device

Android still not working on new version. I use windows 7

Android still not working on Windows (10)

Android still not working on Windows 10

As of midnight east coast, Android Windows 10 not working.

I am still facing same error even after changing version to 0.58.6. The only thing that works is to always do
'''react-native start --reset-cache in one terminal and leave it open
react-native run-android in another terminal'''

How can i stop this permanently

On Linux Still not working on the android device, working fine in android simulator

Yes, I am also facing the same issue version 0.58.1 and 0.58.2. I just created a project "react-native init test" and then "react-native run-android" and I get this one
Screenshot_20190327-112725

How can I solve this one

I don't have access to a Windows PC at the moment to triage this - I will do near the end of the week if someone doesn't beat me to it.

For reference; https://github.com/facebook/react-native/commit/392b0845ce624de0632721c67d349455e5029715#diff-fe2ea122979e8bb9729dff893828ae61 was the commit that fixed this for linux/osx - my guess is similar needs applying to ./scripts/launchPackager.bat.

Temporary workaround for Windows users
Go to your PROJECT_FOLDER/node_modules/react-native/scripts
Open the file launchPackager.bat with your favorite text editor and add this line

cd "%~dp0..\..\..\"

as follows

@echo off
title Metro Bundler
call .packager.bat
cd "%~dp0..\..\..\"
node "%~dp0..\cli.js" start
pause
exit

Then run react-native run-android normally

Temporary workaround (Windows 10 users)
Go to your PROJECT_FOLDER/node_modules/react-native/scripts
Open the file launchPackager.bat with your favorite text editor and add this line

cd "%~dp0..\..\..\"

as follows

@echo off
title Metro Bundler
call .packager.bat
cd "%~dp0..\..\..\"
node "%~dp0..\cli.js" start
pause
exit

I've only tested it in the simulator, give it a try.

I can confirm that your solution works on my Windows 8.1 on physical Android device!

Temporary workaround (Windows 10 users)
Go to your PROJECT_FOLDER/node_modules/react-native/scripts
Open the file launchPackager.bat with your favorite text editor and add this line

cd "%~dp0..\..\..\"

as follows

@echo off
title Metro Bundler
call .packager.bat
cd "%~dp0..\..\..\"
node "%~dp0..\cli.js" start
pause
exit

I've only tested it in the simulator, give it a try.

This Workaround works on Win10 with "react-native": "0.59.2" on physical and virtual Device

I'm facing the same issue with react-native run-ios command on the RNV "0.59.1"

Temporary workaround for Windows users
Go to your PROJECT_FOLDER/node_modules/react-native/scripts
Open the file launchPackager.bat with your favorite text editor and add this line

cd "%~dp0..\..\..\"

as follows

@echo off
title Metro Bundler
call .packager.bat
cd "%~dp0..\..\..\"
node "%~dp0..\cli.js" start
pause
exit

Then run react-native run-android normally

Works

@IamStephan it's works for my your wka. thanks

Hey all, there's been a fix for this in https://github.com/facebook/react-native/commit/9db347fabca19c66f669faf4054c81cc3624be03 - we'll look at getting this in a patch release hopefully - e.g. 0.59.3.

Thanks

Screenshot_1553876630

is not a work in code on terminal
react-native start --reset-cache
react-native start -- --reset-cache

i am a beginner in react native and i am also getting Can't run a fresh new project (unable to resolve module ./index) issue on 0.59.0 , 0.59.1 and 0.59.2 versions. what to do?

@ashu777 just wait for 0.59.3 release!

Temporary workaround for Windows users
Go to your PROJECT_FOLDER/node_modules/react-native/scripts
Open the file launchPackager.bat with your favorite text editor and add this line

cd "%~dp0..\..\..\"

as follows

@echo off
title Metro Bundler
call .packager.bat
cd "%~dp0..\..\..\"
node "%~dp0..\cli.js" start
pause
exit

Then run react-native run-android normally

Works with WIN10 + Android VD (RN 0.59.2). Thanks.

Hey everyone - we just released 0.59.3 (changelog coming soon) which should have the needed fix for this issue, can anyone try to upgrade and lmk if it's fixed?

This happens to me in 0.59.0, 0.59.1, 0.59.2, and 0.59.3, on macOS.

error: bundling failed: Error: Unable to resolve module `./../../../../../usr/local/lib/node_modules/@react-native-community/cli/node_modules/react-transform-hmr/lib/index.js` from `/Users/dcg/Desktop/git/testApp/index.js`: The module `./../../../../../usr/local/lib/node_modules/@react-native-community/cli/node_modules/react-transform-hmr/lib/index.js` could not be found from `/Users/dcg/Desktop/git/tesetApp/index.js`. Indeed, none of these files exist:
  * `/usr/local/lib/node_modules/@react-native-community/cli/node_modules/react-transform-hmr/lib/index.js(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)`
  * `/usr/local/lib/node_modules/@react-native-community/cli/node_modules/react-transform-hmr/lib/index.js/index(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)`
    at ModuleResolver.resolveDependency (/usr/local/lib/node_modules/@react-native-community/cli/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:163:15)
    at ResolutionRequest.resolveDependency (/usr/local/lib/node_modules/@react-native-community/cli/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (/usr/local/lib/node_modules/@react-native-community/cli/node_modules/metro/src/node-haste/DependencyGraph.js:283:16)
    at Object.resolve (/usr/local/lib/node_modules/@react-native-community/cli/node_modules/metro/src/lib/transformHelpers.js:261:42)
    at dependencies.map.result (/usr/local/lib/node_modules/@react-native-community/cli/node_modules/metro/src/DeltaBundler/traverseDependencies.js:399:31)
    at Array.map (<anonymous>)
    at resolveDependencies (/usr/local/lib/node_modules/@react-native-community/cli/node_modules/metro/src/DeltaBundler/traverseDependencies.js:396:18)
    at /usr/local/lib/node_modules/@react-native-community/cli/node_modules/metro/src/DeltaBundler/traverseDependencies.js:269:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/usr/local/lib/node_modules/@react-native-community/cli/node_modules/metro/src/DeltaBundler/traverseDependencies.js:87:24)

This also: react-native bundle --platform ios --dev false --entry-file index.js --bundle-output ios-release.bundle --sourcemap-output ios-release.bundle.map, to generate sourcemaps, fails with SHA-1 for file (......./empty-module.js) is not computed.

https://github.com/facebook/react-native/issues/24188

I think this is the exact same bug.


To be clear, I tried:

  1. rm -rf node_modules && npm i
  2. react-native start --reset-cache
  3. rm -rf /tmp/metro-bundler-cache-*
  4. watchman watch-del-all

Nothing worked.

I can confirm that is working on Win10!

me too, wait for 0.59.3.

Ok closing for now, let's reopen if it's actually still an issue (please provide a repro for 0.59.3)

@kelset it IS reproduced for me on a fresh 0.59.3 project

The issue you reported is a different one, which is related to source maps - and I have replied to you about it in the other issue.

You can do this : react-native start --reset-cache then run agein

For you all that are trying to get a fresh project, just use the version 0.58.6 of RN, the error does not appear in there. To do this just use the command react-native init projectName --version [email protected] and be happy coding

it is (0.59.3) working on windows 10.

Same problem on 0.59.1 after hitting the play button in Xcode.

Confirming react-native start --reset-cache fixes this on macOS

this work for me too.

Work on windows 10 with 0.59.3

I'm using expo. I tried react-native start --reset-cache, I tried expo start -c. Didn't work.

'React/RCTBridgeDelegate.h' file not found
Screen Shot 2019-07-23 at 10 39 04 AM

@evabhivyas What is your React version?
If it's pre 0.60, you likely forgot to run pod install. Or it could be that you need to add "React" as part of your schemes if you aren't using Pods.
If it's >= 0.60, it could be pod install or one of your SDKs might not be compatible with RN 0.60 yet, because of the new autolinking system. See https://github.com/react-native-community/cli/blob/master/docs/autolinking.md for more details.

Was this page helpful?
0 / 5 - 0 ratings