react-native报错-Unable to resolve module ‘react’

Reprint  https://blog.csdn.net/mapbar_front/article/details/76165239

error: bundling failed: “Unable to resolve module react from C:\\Users\\liwd\\Desktop\\mywork\\react-native\\Navigator\\index.android.js: Module does not exist in the module map\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n 

1. Clear watchman watches: watchman watch-del-all.\n 

2.Delete the node_modules folder: rm -rf node_modules && npm install.\n 

3. Reset packager cache: rm -fr $TMPDIR/react-* or npm start -- --reset-cache.”

Reason for error: A Module  referenced by import in  index.android.js cannot be found.

First possibility: 

Solution: delete node_modules folder, reload. Or, open the node_modules folder to see if the file is placed elsewhere, and re-import it after finding it.
npm install
  • 1

The second possibility: 
the versions of react and react-native do not match  . Different versions of react and react-native will conflict. The feasibility of 
downloading the specified version of react and react-native  : directly select the react and react-native after react-native init. react-native version, then delete node_modules, and then do npm install.

Problems you may have: When npm a new package such as react-native-vector-icons, it is best to delete node_modules and re-npm install. Because of this some unknown error may occur.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325506463&siteId=291194637