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

本文总结了在ReactNative 0.57.2版本中遇到的五个常见问题及其解决方案,包括无法识别run-android命令、bundling失败、Accessibility DelegateUtil类型错误、Navigator组件废弃及script加载失败等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

第一次运行 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’

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值