React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:

无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。

我做错了什么?


当前回答

试试这个

taskkill /F /IM node.exe

然后

npx react-native run-android

其他回答

你也可以把node js降级到小于12的版本,然后删除nodemodule,然后再次运行NPM install

在某些情况下,您可能需要关闭React-native捆绑器的端口 用相同的进程重新运行应用程序

1.sudo kill -9 $(sudo lsof -t -i:9001)

2.npm start inside the project

3. react-native run-android

(快速回答)

在我的工作空间尝试解决这个问题后,我找到了一个解决方案。

此错误是因为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.

执行如下两条命令

亚行kill-server 亚洲开发银行启动服务器

在这之后,运行npm start命令,然后按下Android studio中常见的绿色运行按钮。

在重命名我的android包ID后,我在React Native v0.69中遇到了这个问题。

将/android/app/src/debug/java/old_package_name重命名为 /android/app/src/debug/java/new_package_name,我不小心将AndroidManifest.xml的调试版本移动到新创建的路径中。

在把它移回/android/app/src/debug/后,yarn android又可以正常工作了,没有做任何其他的解决方案。有趣的是,这个错误导致了这个错误,所以如果它发生在其他人身上,检查确保你的文件在他们应该在的地方。