react-native-community / cli

The React Native Community CLI - command line tools to help you build RN apps
MIT License
2.34k stars 899 forks source link

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

Closed thecodrr closed 5 years ago

thecodrr commented 5 years ago

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
thymikee commented 5 years ago

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

thecodrr commented 5 years ago

@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 commented 5 years ago

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

thecodrr commented 5 years ago

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

thymikee commented 5 years ago

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

thecodrr commented 5 years ago

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

thecodrr commented 5 years ago

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 commented 5 years ago

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

thymikee commented 5 years ago

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 commented 5 years ago

@thymikee yup. Working without a hitch.

thymikee commented 5 years ago

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 commented 5 years ago

@thymikee okay, I will do that.

zenz commented 5 years ago

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 commented 5 years ago

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

-node "%~dp0..\cli.js" --projectRoot ../../../ start
+node "%~dp0..\cli.js" start
zenz commented 5 years ago

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

thecodrr commented 5 years ago

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

thymikee commented 5 years ago

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

zenz commented 5 years ago

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 commented 5 years ago

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

victorwpbastos commented 5 years ago

Maybe projectRoot parameter is necessary after all.

zenz commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

@thymikee should I add it to the PR?

thymikee commented 5 years ago

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

thecodrr commented 5 years ago

@thymikee after adding the cd command, the packager loads and bundles successfully. So it is working.

victorwpbastos commented 5 years ago

After the cd ../../../ command, it works successfully!

Inovassist-dev commented 5 years ago

Hey guys, still having problems... Today I started a new RN project, after the setupe, my Metro Bundler opens, starts, but it keeps in the "Loading Depedency Graph..." screen. It starts to consume my computer memory like crazy and everything gets really slow, but the Metro Bundler don't finish the Dependency Graph proccess. Any workaround to that?

P.S.: I already tried the steps above!

zenz commented 5 years ago

@Inovassist-dev kill all background node process, run react-native start is it running correct or not?

Andersonfrfilho commented 5 years ago

Thx, zenz I have this problem

Environment

System:
    OS: Windows 10
Yarn version: 
  1.16.0

Node version: 
  10.15.3

Platform: 
  win32 x64

react-native --version

react-native-cli: 2.0.1
react-native: 0.60.0

react-native run-android

`D:\ADS\curso-react-native\ReactNativeReduxGraphQl>react-native run-android info Starting JS server... info Installing the app...

Task :app:installDebug 01:20:29 V/ddms: execute: running am get-config 01:20:29 V/ddms: execute 'am get-config' on 'emulator-5554' : EOF hit. Read: -1 01:20:29 V/ddms: execute: returning Installing APK 'app-debug.apk' on 'Pixel_3_API_28_86(AVD) - 9' for app:debug 01:20:29 D/app-debug.apk: Uploading app-debug.apk onto device 'emulator-5554' 01:20:29 D/Device: Uploading file onto device 'emulator-5554' 01:20:29 D/ddms: Reading file permision of D:\ADS\curso-react-native\ReactNativeReduxGraphQl\android\app\build\outputs\apk\debug\app-debug.apk as: rwx------ 01:20:29 V/ddms: execute: running pm install -r -t "/data/local/tmp/app-debug.apk" 01:20:30 V/ddms: execute 'pm install -r -t "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : EOF hit. Read: -1 01:20:30 V/ddms: execute: returning 01:20:30 V/ddms: execute: running rm "/data/local/tmp/app-debug.apk" 01:20:30 V/ddms: execute 'rm "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : EOF hit. Read: -1 01:20:30 V/ddms: execute: returning Installed on 1 device.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 3s 27 actionable tasks: 2 executed, 25 up-to-date 'C:\Users\Anderson' n�o � reconhecido como um comando interno ou externo, um programa oper�vel ou um arquivo em lotes. info Connecting to the development server... info Starting the app... Starting: Intent { cmp=com.reactnativereduxgraphql/.MainActivity }

D:\ADS\curso-react-native\ReactNativeReduxGraphQl>`

Works only by executing commands 1st react-native start 2nd react-native run-android

or manually the project repositori https://github.com/Andersonfrfilho/ReactNativeReduxGraphQl

thecodrr commented 5 years ago

@Andersonfrfilho I don't see any error in your output. What's the problem?

zenz commented 5 years ago

I run @Andersonfrfilho 's code with modified launchPackager.bat. No errors and it runs well. image

So I think he didn't modify the launchPackager.bat file

thecodrr commented 5 years ago

Just created a PR (#489) that should fix this for now. @thymikee waiting for your review.

zenz commented 5 years ago

@theweavrs good, this PR moves the commands into same place.

ruhaim commented 5 years ago

Just created a PR (#489) that should fix this for now. @thymikee waiting for your review.

when i applied the pr, i get a "fs is not defined error"

EnKrypt commented 5 years ago

As a temporary solution, I've found a little workaround :

You might be stuck with a blank screen after this, meaning you have to run again after Metro generated a build/bundle once. So force close the app, and then run as usual again while keeping the Metro Bundler running in the background.

You may also have to update your version of react-native-cli to 2.0.2

Andersonfrfilho commented 5 years ago

Good as I saw the difficulty to find the error I posted a video showing what is happening now when I execute the commands https://youtu.be/6qiBeKnHYSc thank you to the impenetrate for trying to solve the problem

zenz commented 5 years ago

@Andersonfrfilho Please read above comments to find out the temporary solution. Sometimes the official release will be very late. Modify node_modules/react-native/scripts/launchPackager.bat Change the contents like below:

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

Again I apologize for the inconvenience, but there is neither this executable nor the file in my node_modules

img: https://ibb.co/kBnmCzG

and https://ibb.co/9y2ddQt

thymikee commented 5 years ago

@Andersonfrfilho the path is ./node_modules/react-native/scripts/launchPackager.bat, please read carefully.

Andersonfrfilho commented 5 years ago

sorry, I just review here I'll try, thx

Andersonfrfilho commented 5 years ago

Hey guys worked with the change in the .bat file ok, vlw but once thanks. Sorry for the inconvenience

thymikee commented 5 years ago

Closed via https://github.com/react-native-community/cli/pull/489. Published in 2.1.1, please try give it a try (see how to update the CLI)

naderabdalghani commented 5 years ago

image The changes in the .bat file made the metro bundler run without closing immediately. However, the metro bundler takes too long to load the dependency graph and then the app crashes in the emulator as soon as the BUNDLE process reaches 100%.

I'm running React Native 0.60 and I've updated @react-native-community/cli to 2.1.2

thymikee commented 5 years ago

@naderabdalghani I suppose you use Node >=12.5, please downgrade to 12.4. See https://github.com/react-native-community/cli/issues/485#issuecomment-509210382

naderabdalghani commented 5 years ago

Memory usage has significantly improved after downgrading to node 12.4.0. However, the app still crashes after BUNDLE process reaches 100% or I manually open it image

thymikee commented 5 years ago

@naderabdalghani That's different issue, likely caused by configuration in your app. Please try a new project with a set of libraries you use and try to find the bug. If you're then sure it's something inside React Native or CLI, please file an issue accordingly.

DaviRJ commented 5 years ago

Same error on Linux (Elementary OS) After running react-native start, i've got a blank screen. For a temporary fix, this work's fine.

arryanggaputra commented 5 years ago

Metro cannot start, so I run react-native start then I got this error, anyone know how to fix this?

events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: UNKNOWN: unknown error, lstat 'D:\WarungPintar\kurir-app\node_modules\.bin\JSONStream'
Emitted 'error' event at:
    at NodeWatcher.checkedEmitError (D:\WarungPintar\kurir-app\node_modules\metro\node_modules\sane\src\node_watcher.js:143:12)
    at Walker.emit (events.js:198:13)
    at D:\WarungPintar\kurir-app\node_modules\walker\lib\walker.js:52:12
    at D:\WarungPintar\kurir-app\node_modules\graceful-fs\polyfills.js:282:31
    at FSReqWrap.oncomplete (fs.js:153:21)
abhirup03 commented 5 years ago

I have recently upgraded to RN 0.60.0 from 0.57, after running "react-native run-android" the configurations from build.grade executes successfully. But the metro bundler launches and doesn't loads and says it's done. The app crashes, as the metro bundler doesn't run.

Any approach to fix this? @thymikee Screen Shot 2019-08-23 at 10 43 46 AM

thymikee commented 5 years ago

Does running react-native start first help? Also, if you use Node 12, make sure to upgrade to 12.9+, there was a bug in V8 that affected Metro.