在android模拟器中运行react native应用时出现以下错误
react-native run-android
已完成加载依赖关系图。
错误:捆绑失败:错误:无法从./../../react-transform-hmr/lib/index.js
解析模块D:\LW_Mobile\Projects\helloworld\App.js
:从./../../react-transform-hmr/lib/index.js
找不到模块D:\LW_Mobile\Projects\helloworld\App.js
。实际上,这些文件都不存在:
* D:\LW_Mobile\react-transform-hmr\lib\index.js(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
我的包裹。杰森是
{
"name": "helloworld",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"@babel/runtime": "^7.1.2",
"babel-preset-react-native": "^4.0.1",
"react": "16.5.0",
"react-native": "0.57.2"
},
"devDependencies": {
"babel-jest": "23.6.0",
"babel-plugin-functional-hmr": "^1.0.24",
"babel-plugin-react-transform": "^3.0.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.48.0",
"react-test-renderer": "16.5.0",
"react-transform-hmr": "^1.0.4"
},
"jest": {
"preset": "react-native"
}
}
babelrc如下
{
"presets": ["es2015", "react", "module:metro-react-native-babel-preset"]
}
注意:与EXPO的运行正常,这是我第一次使用 react-native run-android 命令
系统正在寻找一些不同的路径,而不是在Node_Module中。与此有关吗??
答案 0 :(得分:1)
您可以通过以下步骤对其进行修复:
关闭以打开所有终端或cmd。
替换package.json中的依赖项
“反应”:“ 16.5.0”, “ react-native”:“ 0.57.1”
执行此命令。
答案 1 :(得分:0)
经过很多努力后找到了解决方案。