cli icon indicating copy to clipboard operation
cli copied to clipboard

Metro Bundler immediately closes after react-native run-android

Open thecodrr opened this issue 7 years ago • 85 comments

Environment

System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 8.99 GB / 15.89 GB
  Binaries:
    Node: 10.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.16.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
  SDKs:
    Android SDK:
      Android NDK: 18.1.5063045
  IDEs:
    Android Studio: Version  3.3.0.0 AI-182.5107.16.33.5264788
react-native-cli: 2.0.1
react-native: 0.60.0

Description

Doing yarn react-native run-android opens the metro bundler but it immediately closes. Don't know if its a bug with the cli or the metro itself. This only happens on Windows, I think.

Things I have tried:

  1. Restarting my system
  2. Clearing cache etc.

Reproducible Demo

  1. Create a new project using react-native init
  2. Run yarn react-native run-android

thecodrr avatar Jul 05 '19 14:07 thecodrr

@naderabdalghani I suppose you use Node >=12.5, please downgrade to 12.4. See #485 (comment)

It worked for me. Thanks

Thanks It worked for me. running 13.1.0 not worked. downgraded to 12.4.0 and it worked. :)

rbalaga avatar Nov 20 '19 16:11 rbalaga

I also downgraded to 12.4.0 and it worked

If you are using chocolatey on windows

choco uninstall nodejs then choco install nodejs --version 12.4.0

gBusato avatar Nov 23 '19 09:11 gBusato

Same here, downgrading node from v12.13.1 to 12.4.0 to work

pjunior94 avatar Nov 23 '19 13:11 pjunior94

I have the same issue with version 3.0.4, which is the latest right now, should I open a new issue?

hosseinalipour avatar Nov 28 '19 11:11 hosseinalipour

I also downgraded to 12.4.0 and it worked

If you are using chocolatey on windows

choco uninstall nodejs then choco install nodejs --version 12.4.0

Confirmed that it's working aswell.

feliperugai avatar Dec 03 '19 17:12 feliperugai

@zenz it's not about rmeoving the file, but doing this diff:

-node "%~dp0..\cli.js" --projectRoot ../../../ start
+node "%~dp0..\cli.js" start

where can i find the file to modify

samdsg avatar Jan 01 '20 16:01 samdsg

nodemodules/react-native/scripts/launchPackager.bat

Pk1631037 avatar Jan 05 '20 14:01 Pk1631037

Actually, this work for me. https://github.com/expo/expo-cli/issues/1074#issuecomment-546167583

cvallejoec avatar Jan 14 '20 00:01 cvallejoec

Environment

System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 8.99 GB / 15.89 GB
  Binaries:
    Node: 10.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.16.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
  SDKs:
    Android SDK:
      Android NDK: 18.1.5063045
  IDEs:
    Android Studio: Version  3.3.0.0 AI-182.5107.16.33.5264788
react-native-cli: 2.0.1
react-native: 0.60.0

Description

Doing yarn react-native run-android opens the metro bundler but it immediately closes. Don't know if its a bug with the cli or the metro itself. This only happens on Windows, I think.

Things I have tried:

  1. Restarting my system
  2. Clearing cache etc.

Reproducible Demo

  1. Create a new project using react-native init
  2. Run yarn react-native run-android

Open Your Project Folder in IDE like Visual Studio Code etc

Click on node_modules folder

Click on metro-config folder

Click on src folder

Click on default folder

Open blacklist.js file and replace the following code var sharedBlacklist = [ /node_modules[/\\]react[/\\]dist[/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ]; With var sharedBlacklist = [ /node_modules[\/\\]react[\/\\]dist[\/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ];

MAsad-Nawaz avatar Feb 04 '20 04:02 MAsad-Nawaz

guys any other solution? I tried everything but my bundler close immediately and unable to run the app. it was working fine but I just reinstall window and below is the configuration:

System: OS: Windows 10 Binaries: Node: 12.4.0 npm: 6.9.0 react-native-cli: 2.0.1 react-native: 0.58.3

I really need this fix. Any quick help would appreciate it

aamir-munir avatar May 19 '20 08:05 aamir-munir

What is the status of this? I'm still experiencing this error, the metro bundle closing with running react-native run-android on node 12.9.1

netgfx avatar Oct 28 '20 07:10 netgfx

In my case I intentionally uninstalled app from emulator and faced the issue. Tried all options but changing app name is the best option. Else reinstall android studio with a new emulator.

whatdtech avatar Oct 31 '20 09:10 whatdtech

Try changing app name in app.Json, build.gradle, AndroidManifest.xml in both debug and main folders

whatdtech avatar Oct 31 '20 09:10 whatdtech

In mac env I also had the same issue and the solution was: brew install nvm && brew unlink node && nvm install v10.23.0 && nvm use v10.23.0 && nvm alias default v10.23.0 then react-native run-android worked like a charm no single error.

engineerbaraazakariya avatar Dec 09 '20 18:12 engineerbaraazakariya

Environment

System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 8.99 GB / 15.89 GB
  Binaries:
    Node: 10.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.16.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
  SDKs:
    Android SDK:
      Android NDK: 18.1.5063045
  IDEs:
    Android Studio: Version  3.3.0.0 AI-182.5107.16.33.5264788
react-native-cli: 2.0.1
react-native: 0.60.0

Description

Doing yarn react-native run-android opens the metro bundler but it immediately closes. Don't know if its a bug with the cli or the metro itself. This only happens on Windows, I think. Things I have tried:

  1. Restarting my system
  2. Clearing cache etc.

Reproducible Demo

  1. Create a new project using react-native init
  2. Run yarn react-native run-android

Open Your Project Folder in IDE like Visual Studio Code etc

Click on node_modules folder

Click on metro-config folder

Click on src folder

Click on default folder

Open blacklist.js file and replace the following code var sharedBlacklist = [ /node_modules[/\\]react[/\\]dist[/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ]; With var sharedBlacklist = [ /node_modules[\/\\]react[\/\\]dist[\/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ];

I'm using node v16.3.0 and this adjustment you posted made it work.. tks

charleston10 avatar Jun 22 '21 18:06 charleston10

For me it was because I had "type": "module" in my package.json

paulwongx avatar Aug 26 '21 01:08 paulwongx

I was having this issue but wasn't able to resolve it with any of the earlier solutions. In the end it turned out my computer had a process binding the default port. Running with a custom port worked great until I restarted, then things were back to normal.

npx react-native run-android --port 8283 (random port)

ZECTBynmo avatar Oct 25 '21 18:10 ZECTBynmo

i always this same problem and the error is usually some file in node_modules was unavailable, if i just continue to press play from android studio it eventually works but sometimes it takes up to 10 tries. any ideas ?

cparello avatar Nov 05 '21 18:11 cparello

@cparello Switch to Flutter for 100% guaranteed builds, Android and iOS, every single time!

I got bored to fight the compiler, did the switch and never looked back!

netgfx avatar Nov 05 '21 20:11 netgfx

How is this still an issue? Its such a waste of time to compile the code from like 15th time because the metro keeps exiting when the build is at 95-99%. I updated the package but not fixed, tried various fixes from the comments above - nothing.

SourceCipher avatar Jul 14 '22 17:07 SourceCipher