我试图在我的设备上第一次运行我的第一个React Native项目(Android 4.2.2)。

我得到:

无法从assets index.android.bundle中加载脚本

我使用的命令:

CD(项目目录) react-native开始 react-native运行android


当前回答

使用npm 4.3.0版本的react-native-cli

在项目目录中,

mkdir android / app / src / main /资产 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 react-native运行android

文件名由index.android.js更改为index.js

其他回答

在命令之前使用NPX对我来说是有效的,命令就像下面这样。

npx 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

为什么我们使用npx,这里是npx和npm之间的区别?

在Windows上

如果你确定node.js已经成功安装在你的系统上,请检查系统环境变量并在系统变量路径中添加C:\windows\system32

在MAC或Windows上,我们可以在1秒内解决这个问题

在你的项目中搜索project.ext.react这个术语

并在bundleInDebug: true中做一个更改,添加这一行。并再次运行您的项目。

    project.ext.react = [
    entryFile: "index.js",
    enableHermes: true,  // clean and rebuild if changing
    bundleInDebug: true  // **add this line only**
]

提出一个显而易见的建议,对我很有用。删除应用程序,重新启动服务器,重新从工具部署到设备。

确保metro构建器正在运行,以使物理设备和服务器同步

首先,运行这个命令来运行metro builder

npm开始

然后你可以在react native中开始构建

react-native运行android

他们这次应该不会出错了。如果您希望您的代码在更改时重新加载。摇动你的设备,然后点击“启用Live Reload”