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

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