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

Metro Bundler immediately closes after react-native run-android #484

Closed
thecodrr opened this issue Jul 5, 2019 · 85 comments
Closed

Metro Bundler immediately closes after react-native run-android #484

thecodrr opened this issue Jul 5, 2019 · 85 comments
Labels
bug Something isn't working env: windows help wanted

Comments

@thecodrr
Copy link
Contributor

thecodrr commented Jul 5, 2019

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 thecodrr added the bug Something isn't working label Jul 5, 2019
@thymikee
Copy link
Member

thymikee commented Jul 5, 2019

We'll need help debugging what's causing this. What does it mean that "it closes"? Can you share more details?

@thecodrr
Copy link
Contributor Author

thecodrr commented Jul 5, 2019

@thymikee well I can't see the error on it as it only blinks. How can I debug it?

Edit: after looking really closely, the Metro Bundler window is completely empty when it closes, so no error there.

@thymikee
Copy link
Member

thymikee commented Jul 5, 2019

Can you post a video? :D Set up some console.logs in commands/server/runServer.js

@thecodrr
Copy link
Contributor Author

thecodrr commented Jul 5, 2019

@thymikee runServer gives nothing so it's not even getting there.

@thymikee
Copy link
Member

thymikee commented Jul 5, 2019

Btw, does running yarn react-native start works without issues? If so, check files related to this diff: #310

@thecodrr
Copy link
Contributor Author

thecodrr commented Jul 5, 2019

Running launchPackager.bat directly gives this error:
error: unknown option --projectRoot'`

@thecodrr
Copy link
Contributor Author

thecodrr commented Jul 5, 2019

Doing yarn react-native start gives me the console.logs I had set so I am guessing, runServer is getting called in that case.

@thecodrr
Copy link
Contributor Author

thecodrr commented Jul 5, 2019

Running node .\node_modules\react-native\cli.js --projectRoot also gives this error:
error: unknown option `--projectRoot'

@thymikee
Copy link
Member

thymikee commented Jul 5, 2019

Yea, because we removed this option. It's not necessary now. Can you remove it from https://github.com/facebook/react-native/blob/master/scripts/launchPackager.bat and see if that works?

@thecodrr
Copy link
Contributor Author

thecodrr commented Jul 5, 2019

@thymikee yup. Working without a hitch.

@thymikee
Copy link
Member

thymikee commented Jul 5, 2019

Yea, can you send a PR to RN? The patch release make take a while (cc @kelset). I think we should own these files, but that may be a bit bigger change.

@thecodrr
Copy link
Contributor Author

thecodrr commented Jul 5, 2019

@thymikee okay, I will do that.

@zenz
Copy link

zenz commented Jul 5, 2019

removing node_modules/react-native/scripts/launchPackager.bat then even the splash window of Metro Bundler will not show, of course it's not running.

@thymikee
Copy link
Member

thymikee commented Jul 5, 2019

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

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

@zenz
Copy link

zenz commented Jul 5, 2019

@thymikee oops... yes, it's working now.

@thecodrr
Copy link
Contributor Author

thecodrr commented Jul 5, 2019

@thymikee can't we ship a temporary fix with the cli until RN releases the fix?

@thymikee
Copy link
Member

thymikee commented Jul 5, 2019

If you'd like to contribute this then of yea. I don't have too much bandwidth currently, just trying to be helpful.

@zenz
Copy link

zenz commented Jul 5, 2019

It seems that another problem raised after modify this launchPackager.bat file. Metro Bundler tells me there's no index file
Error: Unable to resolve module ./indexfromC:\Users\zenz\programs\test_app\node_modules\react-native\scripts/.: The module ./indexcould not be found fromC:\Users\zenz\programs\test_app\node_modules\react-native\scripts/.. Indeed, none of these files exist:
But using react-native start to start the Metro Bundler is working correctly.

@victorwpbastos
Copy link
Contributor

@zenz same here. I changed lanchPackager.bat, Metro bundler shows up, but with this error.

@victorwpbastos
Copy link
Contributor

Maybe projectRoot parameter is necessary after all.

@zenz
Copy link

zenz commented Jul 5, 2019

modify it like this, solves the problem:

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

hard coding it to swith to root directory.

@thymikee
Copy link
Member

thymikee commented Jul 5, 2019

I think that makes sense, this is similar to what Linux script does: https://github.com/facebook/react-native/blob/master/scripts/launchPackager.command

@thecodrr
Copy link
Contributor Author

thecodrr commented Jul 5, 2019

@thymikee should I add it to the PR?

@thymikee
Copy link
Member

thymikee commented Jul 5, 2019

Let's make sure it works as intended, and then yes

@JindalPrashant
Copy link

I was using node 12.13.0 and facing the same issue. Now I downgraded it to 10.15.0 and metro bundle is running without fail.

@JindalPrashant
Copy link

JindalPrashant commented Nov 15, 2019

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

It worked for me. Thanks

@rbalaga
Copy link

rbalaga commented Nov 20, 2019

@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. :)

@gBusato
Copy link

gBusato commented Nov 23, 2019

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

@pjunior94
Copy link

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

@hosseinalipour
Copy link

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

@feliperugai
Copy link

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.

@samdsg
Copy link

samdsg commented Jan 1, 2020

@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

@Pk1631037
Copy link

nodemodules/react-native/scripts/launchPackager.bat

@cvallejoec
Copy link

Actually, this work for me.
expo/expo-cli#1074 (comment)

@MAsad-Nawaz
Copy link

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__\/.*/ ];

@aamir-munir
Copy link

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

@netgfx
Copy link

netgfx commented Oct 28, 2020

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

@whatdtech
Copy link

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
Copy link

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

@engineerbaraazakariya
Copy link

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.

@charleston10
Copy link

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

@paulwongx
Copy link

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

@ZECTBynmo
Copy link

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)

@cparello
Copy link

cparello commented Nov 5, 2021

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 ?

@netgfx
Copy link

netgfx commented Nov 5, 2021

@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!

@SourceCipher
Copy link

SourceCipher commented Jul 14, 2022

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.

@jmmwangi007
Copy link

I'm not too sure if this is the correct solution but opening an new console and running

npx react-native start

works for me.

@khadeshyam
Copy link

I had the same issue.The Metro runs on port 8081.But something else running was running on the port.I resolved by killing that process.refer https://reactnative.dev/docs/troubleshooting for more info

@MattNic2
Copy link

Was a permanent fix ever found for this problem, I'm still experiencing it.
RN version : 0.71.8
RN CLI version: 2.0.1

@szymonrybczak
Copy link
Collaborator

Hey @MattNic2, mind upgarding to the latest version of RN? We fixed few things around starting packager in run-android.

@bertdida
Copy link

For me, quitting the Docker solves my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working env: windows help wanted
Projects
None yet
Development

No branches or pull requests