ReactNative 踩坑之旅: Unable to resolve module 和 Error: Plugin

Unable to resolve module AccessibilityInfo from XXX

Unable to resolve module `AccessibilityInfo` from `xxx\node_modules\react-native\Libraries\
react-native\react-native-implementation.js`: Module does not exist in the module map This might be related to https://github.com/facebook/react-native/issues/4968 To resolve try the following: 1. Clear watchman watches: `watchman watch-del-all`. 2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`. 3. Reset Metro Bundler cache: `rm -rf $TMPDIR/react-*` or `npm start -- --reset-cache`. 4. Remove haste cache: `rm -rf $TMPDIR/haste-map-react-native-packager-*`.

按照报错信息中的四个方法都没有解决此问题, 后来在github的问题讨论中找到了一条不起眼的答案. 
按照上面教程走下来后安装的是最新的ReactNative(现在是0.56), 这个问题可能是新版本的bug, 降级到0.55即可.

降级流程: 
1. 在工程目录下执行 E:\ReactNative\Test>npm install --save [email protected]
2. 然后 E:\ReactNative\Test>react-native upgrade, 这里会提示你要不要覆盖原来的部分文件, 我是一路y, 最后提示 Successfully upgraded this project to react-native v0.55.4
3. 接下来再运行, 提示一个android目录下build错误, 我猜应该是build旧文件的错误, 所以删掉了android目录下的几个build文件夹; 
4. 又有问题( 如果没有这么多问题就跳过这些步骤 ): MainApplication 内找不到 BuildConfig ,代码问题好办, 用AS打开, import BuildConfig 就可以了.

另外, Unable to resolve module react-navigation from 可以用 npm install react-navigation@https://github.com/react-community/react-navigation.git --save 解决.

至此, mission complete, 来到下一个问题(手动滑稽)


Module build failed: Error: Plugin 0 specified in “base” … provided an invalid property of “default”

也是个大红屏错误, 是在babel-preset-react-native包里的文件错误, 看了下那个文件, 没有几行代码.

最后在 https://github.com/facebook/react-native/issues/15545 的回答中找到适合我的方法.

执行 npm install --save-dev [email protected] 后再次运行即可, 终于看到梦寐以求的界面了

猜你喜欢

转载自www.cnblogs.com/whxz/p/9318020.html