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

`react-native run-android` failed auto start js server #1223

Closed CroMarmot closed 2 years ago

CroMarmot commented 4 years ago

Environment

System:
    OS: Linux 4.15 Ubuntu 18.04.4 LTS (Bionic Beaver)
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 4.26 GB / 15.55 GB
    Shell: 4.4.20 - /bin/bash
  Binaries:
    Node: 12.13.0 - /usr/local/bin/node
    Yarn: 1.21.1 - /usr/bin/yarn
    npm: 6.12.0 - /usr/local/bin/npm
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 23, 24, 26, 27, 28, 29
      Build Tools: 22.0.1, 23.0.3, 26.0.0, 28.0.3
      System Images: android-26 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom_64, android-27 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: Not Found
  Languages:
    Java: 1.8.0_252 - /usr/bin/javac
    Python: 2.7.17 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: 0.63.1 => 0.63.1 
  npmGlobalPackages:
    *react-native*: Not Found

Description

yarn android can't start js server,

it print Starting JS server... but start failed, ps -aux | grep node print nothing

and on my android, the app looks like this url

Reproducible Demo

npx react-native init reactNativeDemo
cd reactNativeDemo
yarn android

yarn android without yarn start

More info

if I run yarn start first , then run yarn android it works well on my android, and ps -aux | grep node print

cromarm+ 22302  2.5  0.4 891916 66820 pts/3    Sl+  20:43   0:00 node /usr/share/yarn/bin/yarn.js start
cromarm+ 22324 68.0  0.9 978464 155832 pts/3   Sl+  20:43   0:04 /usr/local/bin/node /home/cromarmot/Desktop/github/reactNativeDemo/node_modules/.bin/react-native start
cromarm+ 22614  0.6  0.1 560588 28928 pts/3    Sl+  20:44   0:00 /usr/local/bin/node /home/cromarmot/Desktop/github/reactNativeDemo/node_modules/metro/node_modules/jest-worker/build/workers/processChild.js
cromarm+ 22620  1.0  0.1 560588 28932 pts/3    Sl+  20:44   0:00 /usr/local/bin/node /home/cromarmot/Desktop/github/reactNativeDemo/node_modules/metro/node_modules/jest-worker/build/workers/processChild.js
cromarm+ 22627  0.6  0.1 560588 28908 pts/3    Sl+  20:44   0:00 /usr/local/bin/node /home/cromarmot/Desktop/github/reactNativeDemo/node_modules/metro/node_modules/jest-worker/build/workers/processChild.js
cromarm+ 22634  1.0  0.1 560588 28952 pts/3    Sl+  20:44   0:00 /usr/local/bin/node /home/cromarmot/Desktop/github/reactNativeDemo/node_modules/metro/node_modules/jest-worker/build/workers/processChild.js
cromarm+ 22641  0.6  0.1 560588 28916 pts/3    Sl+  20:44   0:00 /usr/local/bin/node /home/cromarmot/Desktop/github/reactNativeDemo/node_modules/metro/node_modules/jest-worker/build/workers/processChild.js
cromarm+ 22648  0.6  0.1 560588 28916 pts/3    Sl+  20:44   0:00 /usr/local/bin/node /home/cromarmot/Desktop/github/reactNativeDemo/node_modules/metro/node_modules/jest-worker/build/workers/processChild.js

Some debug info

I found the source code of Starting JS server..., https://github.com/react-native-community/cli/blob/f76add94dcfb647dd55b59a5fad9a4d5363962fa/packages/platform-android/src/commands/runAndroid/index.ts#L104

I add console.log(passedOptions) below to print the passedOptions

https://github.com/react-native-community/cli/blob/f76add94dcfb647dd55b59a5fad9a4d5363962fa/packages/cli/src/index.ts#L136-L137

it shows

{
  root: '',
  variant: 'debug',
  appFolder: undefined,
  appId: '',
  appIdSuffix: '',
  mainActivity: 'MainActivity',
  deviceId: undefined,
  packager: true,
  port: 8081,
  terminal: 'xterm-256color',
  tasks: undefined,
  jetifier: true
}

and console.log(error) below

https://github.com/react-native-community/cli/blob/f76add94dcfb647dd55b59a5fad9a4d5363962fa/packages/platform-android/src/commands/runAndroid/index.ts#L326-L336

it show

Error: spawnSync xterm-256color ENOENT
    at Object.spawnSync (internal/child_process.js:1041:20)
    at Object.spawnSync (child_process.js:607:24)
    at Function.module.exports.sync (/home/cromarmot/Desktop/github/reactNativeDemo/node_modules/execa/index.js:334:30)
    at startServerInNewWindow (/home/cromarmot/Desktop/github/reactNativeDemo/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:323:31)
    at /home/cromarmot/Desktop/github/reactNativeDemo/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:137:9
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Command.handleAction (/home/cromarmot/Desktop/github/reactNativeDemo/node_modules/@react-native-community/cli/build/index.js:188:9) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawnSync xterm-256color',
  path: 'xterm-256color',
  spawnargs: [
    '-e',
    'sh /home/cromarmot/Desktop/github/reactNativeDemo/node_modules/react-native/scripts/launchPackager.command'
  ],
  stdout: null,
  stderr: null,
  failed: true,
  signal: null,
  cmd: 'xterm-256color -e sh /home/cromarmot/Desktop/github/reactNativeDemo/node_modules/react-native/scripts/launchPackager.command',
  timedOut: false
}
vijfhoek commented 4 years ago

Might be fixed with my PR #1230 in combination with specifying your terminal (react-native run-android --terminal gnome-terminal)

CroMarmot commented 2 years ago

Sorry, my operating system and related environment have been upgraded, and I haven't used RN for a long time. Now there is no environment to reproduce this problem, so I will close this issue first.