Metro Bundler immediately closes after react-native run-android
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:
- Restarting my system
- Clearing cache etc.
Reproducible Demo
- Create a new project using
react-native init - Run
yarn react-native run-android
We'll need help debugging what's causing this. What does it mean that "it closes"? Can you share more details?
@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.
Can you post a video? :D Set up some console.logs in commands/server/runServer.js
@thymikee runServer gives nothing so it's not even getting there.
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
Running launchPackager.bat directly gives this error:
error: unknown option --projectRoot'`
Doing yarn react-native start gives me the console.logs I had set so I am guessing, runServer is getting called in that case.
Running node .\node_modules\react-native\cli.js --projectRoot also gives this error:
error: unknown option `--projectRoot'
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 yup. Working without a hitch.
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 okay, I will do that.
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 it's not about rmeoving the file, but doing this diff:
-node "%~dp0..\cli.js" --projectRoot ../../../ start
+node "%~dp0..\cli.js" start
@thymikee oops... yes, it's working now.
@thymikee can't we ship a temporary fix with the cli until RN releases the fix?
If you'd like to contribute this then of yea. I don't have too much bandwidth currently, just trying to be helpful.
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 same here. I changed lanchPackager.bat, Metro bundler shows up, but with this error.
Maybe projectRoot parameter is necessary after all.