"npx react-native start" 挂起
"npx react-native start" hangs
简介
我正在尝试使用 official docs 使用 React Native 0.63.3 创建一个 Hello World 风格的程序。我正在使用 React Native CLI Quickstart 路径 link.
到目前为止我做了什么
我已经进入了部分:
运行 你的 React Native 应用程序
第 1 步:启动 Metro
我 运行:
npx react-native start --verbose
我得到以下输出:
###### ######
### #### #### ###
## ### ### ##
## #### ##
## #### ##
## ## ## ##
## ### ### ##
## ######################## ##
###### ### ### ######
### ## ## ## ## ###
### ## ### #### ### ## ###
## #### ######## #### ##
## ### ########## ### ##
## #### ######## #### ##
### ## ### #### ### ## ###
### ## ## ## ## ###
###### ### ### ######
## ######################## ##
## ### ### ##
## ## ## ##
## #### ##
## #### ##
## ### ### ##
### #### #### ###
###### ######
debug Checking for a newer version of React Native
debug Current version: 0.63.3
debug Cached release version: 0.60.0
debug Checking for newer releases on GitHub
Welcome to React Native!
Learn once, write anywhere
To reload the app press "r"
To open developer menu press "d"
debug Latest release: 0.60.0
按“r”得到以下结果:
No apps connected. Sending "reload" to all React Native apps failed. Make sure your app is running in the simulator or on a phone connected via USB.
info Reloading app...
按“d”得到以下结果:
warn No apps connected. Sending "devMenu" to all React Native apps failed. Make sure your app is running in the simulator or on a phone connected via USB.
info Opening developer menu...
问题
如何成功 运行 并完成 Metro 进程,以便我可以 运行 我的 React Native 应用程序?
使用 npx react-native start
,您正在 运行 构建,但是,对于 运行 应用程序,您需要选择 运行 android
或 ios
。 source:
android:
npx react-native run-android
ios: (mac)
npx react-native run-ios
正在关注 Set Up React-Native on Your WSL2 for Android Development
和 Building a react native app in WSL2
但是我也有同样的问题
解决方案 - Result
- 创建资产文件夹
遵循此 link:此错误通常发生是因为系统无法创建包含应用程序中所有 Javascript 代码的初始包。要解决这个问题,首先要在 react-native 项目文件夹中创建一个资产文件夹:
- 转到 wsl 中的项目文件夹或 ubuntu
cd android/app/src/main/
- 创建一个名为 assets 的文件夹
mkdir assets
- 创建包含所有 Javascript 代码的初始包
按照这个 link 到
[your project]/android/app/src/main$ npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
- 如果 adb 使用环境变量配置崩溃,请使用 socat
- 运行 在 PowerShell 中:
adb kill-server ;adb -a -P 5037 nodaemon server
- 运行 在 ubuntu 或 wsl:
socat -d -d TCP-LISTEN:5037,reuseaddr,fork TCP:$(cat /etc/resolv.conf | tail -n1 | cut -d " " -f 2):5037
- 运行 在 NEW PowerShell 中:
$WSL_CLIENT = bash.exe -c "ip addr show eth0 | grep -oP '(?<=inet\s)\d+(.\d+){3}'"
然后
iex "netsh interface portproxy add v4tov4 listenport=8081 listenaddress=127.0.0.1 connectport=8081 connectaddress=$WSL_CLIENT"
简介
我正在尝试使用 official docs 使用 React Native 0.63.3 创建一个 Hello World 风格的程序。我正在使用 React Native CLI Quickstart 路径 link.
到目前为止我做了什么
我已经进入了部分:
运行 你的 React Native 应用程序
第 1 步:启动 Metro
我 运行:
npx react-native start --verbose
我得到以下输出:
###### ######
### #### #### ###
## ### ### ##
## #### ##
## #### ##
## ## ## ##
## ### ### ##
## ######################## ##
###### ### ### ######
### ## ## ## ## ###
### ## ### #### ### ## ###
## #### ######## #### ##
## ### ########## ### ##
## #### ######## #### ##
### ## ### #### ### ## ###
### ## ## ## ## ###
###### ### ### ######
## ######################## ##
## ### ### ##
## ## ## ##
## #### ##
## #### ##
## ### ### ##
### #### #### ###
###### ######
debug Checking for a newer version of React Native
debug Current version: 0.63.3
debug Cached release version: 0.60.0
debug Checking for newer releases on GitHub
Welcome to React Native!
Learn once, write anywhere
To reload the app press "r"
To open developer menu press "d"
debug Latest release: 0.60.0
按“r”得到以下结果:
No apps connected. Sending "reload" to all React Native apps failed. Make sure your app is running in the simulator or on a phone connected via USB.
info Reloading app...
按“d”得到以下结果:
warn No apps connected. Sending "devMenu" to all React Native apps failed. Make sure your app is running in the simulator or on a phone connected via USB.
info Opening developer menu...
问题
如何成功 运行 并完成 Metro 进程,以便我可以 运行 我的 React Native 应用程序?
使用 npx react-native start
,您正在 运行 构建,但是,对于 运行 应用程序,您需要选择 运行 android
或 ios
。 source:
android:
npx react-native run-android
ios: (mac)
npx react-native run-ios
正在关注 Set Up React-Native on Your WSL2 for Android Development 和 Building a react native app in WSL2
但是我也有同样的问题
解决方案 - Result
- 创建资产文件夹
遵循此 link:此错误通常发生是因为系统无法创建包含应用程序中所有 Javascript 代码的初始包。要解决这个问题,首先要在 react-native 项目文件夹中创建一个资产文件夹:
- 转到 wsl 中的项目文件夹或 ubuntu
cd android/app/src/main/
- 创建一个名为 assets 的文件夹
mkdir assets
- 创建包含所有 Javascript 代码的初始包
按照这个 link 到
[your project]/android/app/src/main$ npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
- 如果 adb 使用环境变量配置崩溃,请使用 socat
- 运行 在 PowerShell 中:
adb kill-server ;adb -a -P 5037 nodaemon server
- 运行 在 ubuntu 或 wsl:
socat -d -d TCP-LISTEN:5037,reuseaddr,fork TCP:$(cat /etc/resolv.conf | tail -n1 | cut -d " " -f 2):5037
- 运行 在 NEW PowerShell 中:
$WSL_CLIENT = bash.exe -c "ip addr show eth0 | grep -oP '(?<=inet\s)\d+(.\d+){3}'"
然后
iex "netsh interface portproxy add v4tov4 listenport=8081 listenaddress=127.0.0.1 connectport=8081 connectaddress=$WSL_CLIENT"