React Native 编译运行 显示错误 Cannot find module @babel/core解决方案

最近使用React Native开发项目,本人使用的是指定RN版本0.52.0创建项目,命令如下:
react-native init RNProject --version 0.52.0

但是执行react-native run-android,启动模拟器后报错信息如下:

Failed to load bundle(http://localhost:8081/index.budle?platfrom=android&dev=true&minify=false) with error:(/Users/caishenye/Workspace/reactnative/RNProject/index.js:Cannot find module '@bable/core' (While processing preset:"/Users/caishenye/Workspace/reactnative/RNProject/node_modules/babel-preset-react-native/index.js")(null)

通过网上查找解决方法,总结遇到此类问题,希望能对读者有所帮助,步骤如下:

1.删除babel-preset-react-native最新版本,并将其版本退回至3.0.2

npm unstall babel-preset-react-native
npm install --save-dev babel-preset-react-native@^3.0.2

2.重新启用应用

react-native run-android

总结:
模拟器报错的信息主要是babel编译问题,只要将babel-preset-react-native版本回降至^3.0.2,正常是没有问题的,经个人实测没什么问题!

猜你喜欢

转载自blog.csdn.net/qq_21937107/article/details/88836662