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

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

我做错了什么?


当前回答

    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

其他回答

你还没有启动捆扎机呢。在项目的根目录下运行npm start或react-native start,然后再执行react-native Run -android。

试试这个

taskkill /F /IM node.exe

然后

npx 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-*

在尝试了几种方法后,这对我来说很有效。

在文件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__\/.*/
];

希望这能有所帮助。

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