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

其他回答

在数小时寻找答案之后。解决方案是将节点降级到版本12.4。

在我的例子中,我意识到这个错误只发生在节点版本12.6的react native 0.60版本中。

如果你在linux上,从App根目录打开终端并运行

npm start

然后打开另一个终端窗口并运行:

react-native run-android

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

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

2.npm start inside the project

3. react-native run-android

我得到了同样的问题,在遵循以下步骤后,它得到了解决的问题

清晰的守望人守望:守望人守望一切。 删除“node_modules”文件夹:rm -rf node_modules && npm install。 Reset Metro Bundler cache: rm -rf /tmp/ Metro - Bundler -cache-* 删除急速缓存:rm -rf /tmp/急速-map-react-native-packager-*

    this works for me on ubuntu
    
    1. if you are having node version 17 first downgrade its version:-
    You can use n for node's version management.
    
    this is very easy to use.
    $ npm install -g n
    
    then you can show your node version:
    $ node -v
    v16.13.2
    
    2. create an assets folder inside root of the project:-
    project\android\app\src\main\assets
    set folder name should be assets

3. now the final step implement the given code inside the project folder:- 

$cd project 
/project$ 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

4. after following all these step react-native was successfully running on my pc