1. 程式人生 > >React Native --bundling failed: Error: Unable to resolve module /../react-transform-hmr/lib/index.js

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