React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
当前回答
(快速回答)
在我的工作空间尝试解决这个问题后,我找到了一个解决方案。
此错误是因为Metro使用NPM和Node版本的某些组合时出现了问题。
你有两个选择:
Alternative 1: Try to update or downgrade npm and node version. Alternative 2: Go to this file: \node_modules\metro-config\src\defaults\blacklist.js and change this code: var sharedBlacklist = [ /node_modules[/\\]react[/\\]dist[/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ]; and change to this: var sharedBlacklist = [ /node_modules[\/\\]react[\/\\]dist[\/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ]; Please note that if you run an npm install or a yarn install you need to change the code again.
其他回答
试试下面的方法。
删除Android和IOS文件夹 运行react-native eject 运行react-native Run -android
也许在前面的步骤之后,你执行了npm start -——reset-cache
我有工作,希望能帮到你。
试试这个命令
~/Library/Android/sdk/platform-tools/adb -s emulator-5554 reverse tcp:8081 tcp:8081
首先执行步骤4和5,然后可以运行项目。如果您没有得到结果(步骤4和5),请执行以下步骤
1-尝试降级你的Node版本(当前版本是12.13.1)
choco uninstall nodejs
choco install nodejs --version 12.8
2-添加npm模块的路径(C:\Users\your user name\AppData\Roaming\npm)到系统变量而不是用户变量
3-使用命令全局安装react native
npm install -g react-native-cli
4-进入项目目录的根目录,执行以下命令:
react-native start
5-打开项目根目录下的另一个终端,执行以下命令:
react-native run-android
编辑:
你在用Genymotion ?是,执行以下步骤。
在以上步骤后,如果您得到以下错误?
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
打开你的genymotion,转到:
genymotion菜单->设置-> ADB ->然后选择使用自定义android sdk工具(点击浏览找到sdk位置)
最后,再次运行您的项目。
在尝试了几种方法后,这对我来说很有效。
在文件node_modules\metro-config\src\defaults\blacklist.js中
替换:
var sharedBlacklist = [
/node_modules[/\\]react[/\\]dist[/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
:
var sharedBlacklist = [
/node_modules[\/\\]react[\/\\]dist[\/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
希望这能有所帮助。
我遇到了同样的麻烦,对我来说,问题是adb不在正确的环境路径,错误是告诉你地铁端口,而你在adb,端口被杀死并重新启动。
添加环境变量(ADB)
开放环境变量 从第二帧PATH变量中选择,然后单击下面的编辑选项 点击添加选项 提交sdk平台工具路径C:\Users\ My User \AppData\Local\Android\ sdk \platform-tools
注意:或取决于adb.exe在您的机器中的位置
保存更改
再次运行android build
$ react-native run-android
Or
$ react-native start
$ react-native run-android