React Native --bundling failed: Error: Unable to resolve module /../react-transform-hmr/lib/index.js

前言

第一次运行 React Native,各种问题,坑死!!!
这里总结几个 bug 。
此处针对的 React Native 版本为
"react-native": "0.57.2"

问题一

shangguanluludeMacBook-Pro:Reatc Native shangguanlulu$ react-native run-android
Command run-android unrecognized. Make sure that you have run npm install and that you are inside a react-native project.

原因:没有进入到对应的项目目录里面。
方法:只需 cd 进入项目目录,再次执行 react-native run-android 即可。

问题二

运行 react-native run-android,出现如下错误:
在这里插入图片描述

错误信息:

The development server returned response error code: 500
 
URL: http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false
error: bundling failed: Error: 
Unable to resolve module ./../react-transform-hmr/lib/index.js from /Users/sturm/Desktop/testpro/App.js: 
The module ./../react-transform-hmr/lib/index.js could not be found from /Users/sturm/Desktop/testpro/App.js. 
Indeed, none of these files exist:

这个是官方0.57.2版本的坑,官方挖的,巨坑。
方法:
在终端命令中进行如下操作:

mac 下操作

# Clean cache
  rm -rf $TMPDIR/react-*; rm -rf $TMPDIR/haste-*; rm -rf $TMPDIR/metro-*; watchman watch-del-all
# Start Metro Bundler directly
  react-native start# 
# Now run 
 `react-native run-android` or `react-native run-ios` in another tab

window 下操作

# Clean cache
react-native start --reset-cache
# new cmd tab
react-native run-android

问题三

运行 react-native run-android,出现如下错误:
在这里插入图片描述

错误信息:
java.lang.string cannot be cast to com.facebook.react.uimanager.Accessibility
DelegateUtil$accessibilityRole

方法:
java.lang.string cannot be cast to com.facebook.react.uimanager.Accessibility
DelegateUtil$accessibilityRole

详情
https://github.com/facebook/react-native/issues/21530

问题四

错误信息:
Navigator is deprecated and has been removed from this package. It can now be installed and imported from react-native-deprecated-custom-components instead of react-native. Learn about alternative navigation solutions at http://facebook.github.io/react-native/docs/navigation.html

解决方法:
'Navigator is deprecated and has been removed from this package. It can now be installed ’ +

问题五

错误信息:
unable to load script from assets ‘index.android bundle’ ,make sure your bundle is packaged correctly or youu’re runing a packager server

解决方法:
unable to load script from assets ‘index.android bundle’

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,出现了两个错误信息,分别是"Cannot find module 'react-scripts/package.json'"和"Cannot find module 'react-dev-utils/crossSpawn'"。这些错误通常是由于缺少相应的模块或包导致的。 对于第一个错误"Cannot find module 'react-scripts/package.json'",它表示找不到名为'react-scripts'的模块或包。这通常是由于没有正确安装或配置React项目所需的依赖项导致的。要解决这个问题,你可以尝试以下几个步骤: 1. 确保你已经在项目目录中运行了正确的安装命令,例如使用npm安装依赖项: ```shell npm install ``` 2. 检查你的项目中是否存在'react-scripts'的依赖项,并且已经正确地添加到了package.json文件中的dependencies或devDependencies中。如果没有,请手动添加它: ```shell npm install react-scripts --save ``` 3. 如果你已经正确安装了'react-scripts',但仍然出现错误,请尝试删除node_modules文件夹并重新安装依赖项: ```shell rm -rf node_modules npm install ``` 对于第二个错误"Cannot find module 'react-dev-utils/crossSpawn'",它表示找不到名为'react-dev-utils/crossSpawn'的模块或包。这通常是由于缺少相应的依赖项或配置错误导致的。要解决这个问题,你可以尝试以下几个步骤: 1. 确保你已经在项目目录中运行了正确的安装命令,例如使用npm安装依赖项: ```shell npm install ``` 2. 检查你的项目中是否存在'react-dev-utils'的依赖项,并且已经正确地添加到了package.json文件中的dependencies或devDependencies中。如果没有,请手动添加它: ```shell npm install react-dev-utils --save ``` 3. 如果你已经正确安装了'react-dev-utils',但仍然出现错误,请尝试删除node_modules文件夹并重新安装依赖项: ```shell rm -rf node_modules npm install ``` 请注意,以上步骤是一般性的解决方法,具体的解决方法可能因项目配置和依赖项的不同而有所差异。如果以上步骤无法解决问题,请提供更多的上下文信息,以便我能够更好地帮助你。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值