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

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

thymikee avatar Jul 05 '19 14:07 thymikee

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

thecodrr avatar Jul 05 '19 14:07 thecodrr

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

thymikee avatar Jul 05 '19 14:07 thymikee

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

thecodrr avatar Jul 05 '19 14:07 thecodrr

Btw, does running yarn react-native start works without issues? If so, check files related to this diff: https://github.com/react-native-community/cli/pull/310

thymikee avatar Jul 05 '19 14:07 thymikee

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

thecodrr avatar Jul 05 '19 14:07 thecodrr

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 avatar Jul 05 '19 15:07 thecodrr

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

thecodrr avatar Jul 05 '19 15:07 thecodrr

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?

thymikee avatar Jul 05 '19 15:07 thymikee

@thymikee yup. Working without a hitch.

thecodrr avatar Jul 05 '19 15:07 thecodrr

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.

thymikee avatar Jul 05 '19 15:07 thymikee

@thymikee okay, I will do that.

thecodrr avatar Jul 05 '19 15:07 thecodrr

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.

zenz avatar Jul 05 '19 15:07 zenz

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

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

thymikee avatar Jul 05 '19 15:07 thymikee

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

zenz avatar Jul 05 '19 15:07 zenz

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

thecodrr avatar Jul 05 '19 15:07 thecodrr

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

thymikee avatar Jul 05 '19 15:07 thymikee

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.

zenz avatar Jul 05 '19 15:07 zenz

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

victorwpbastos avatar Jul 05 '19 15:07 victorwpbastos

Maybe projectRoot parameter is necessary after all.

victorwpbastos avatar Jul 05 '19 15:07 victorwpbastos