React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
当前回答
默认情况下,一个名为“Metro server”的小型JavaScript服务器运行在端口8081上。
您需要使此端口可用于此服务器启动。所以,
释放端口 关闭虚拟设备 “react-native run-android”。
如何释放端口?
http://tenbull.blogspot.com/2019/05/how-to-kill-process-currently-using.html
如何在windows中杀死当前使用本地主机端口的进程?
最重要的是,我从8升级了我的节点版本。X到10.x(最新),正如facebook建议的那样 @ https://facebook.github.io/react-native/docs/getting-started
其他回答
默认情况下,一个名为“Metro server”的小型JavaScript服务器运行在端口8081上。
您需要使此端口可用于此服务器启动。所以,
释放端口 关闭虚拟设备 “react-native run-android”。
如何释放端口?
http://tenbull.blogspot.com/2019/05/how-to-kill-process-currently-using.html
如何在windows中杀死当前使用本地主机端口的进程?
最重要的是,我从8升级了我的节点版本。X到10.x(最新),正如facebook建议的那样 @ https://facebook.github.io/react-native/docs/getting-started
(快速回答)
在我的工作空间尝试解决这个问题后,我找到了一个解决方案。
此错误是因为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
npx react-native run-android --port=8082 (maybe port number differs)
你也可以把node js降级到小于12的版本,然后删除nodemodule,然后再次运行NPM install
M1芯片
验证您的JAVA_HOME路径,在我的M1芯片的情况下,我将其定义为.zprofile
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"
然后执行source ~/。终端z型线
在这之后,它对我起作用了。