1、初始化命令,导入所有组件模块:npm install
2、查看当前未处于最新版本的组件包:npm outdated
3、更新指定组件包到指定版本:npm install --save [email protected]
npm install --save 包名@版本号
4、将组件包link到IOS和Android项目中(为IOS和Android添加依赖):react-native link
5、react-native在使用3中的命令更新后,需要进行升级,然后用4的命令进行link:react-native upgrade
6、添加额外组件:npm install react-native-deprecated-custom-components --save
npm install 包名 --save
问题:
1、Exception: undefined is not an object (evaluating '_reactNative.ViewPropTypes.style')
- 升级react-native版本
2、Unable to resolve module AccessibilityInfo from /Users/xuan/Downloads/30-days-of-react-native-development/node_modules/react-native/Libraries/react-native/react-native-implementation.js: Module does not exist in the module map or in these directories:
/Users/xuan/Downloads/30-days-of-react-native-development/node_modules/react-native/node_modules
, /Users/xuan/Downloads/30-days-of-react-native-development/node_modules
, /Users/xuan/node_modules
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 packager cache: `rm -fr $TMPDIR/react-*` or `npm start -- --reset-cache`.
- 依赖问题,执行react-native link命令
3、RCT***,import的问题一般和依赖的版本不一致有关,需要把所有组件升级到最新版本(或者指定版本):
- 首先执行npm outdated,查看过期版本,然后查看编译报错的类,一般一一对应,然后执行更新命令npm install --save [email protected],将相应组件包升级到指定版本,最后最好执行react-native upgrade,执行完毕后重新执行react-native upgrade,更新IOS和Android的依赖包,必要时可能需要重启项目
4、Exception: undefined is not an object (evaluating 'ReactInternals.ReactCurrentOwner')
- 原因是React版本不匹配,因为除了合适的React-native版本,还需要合适的React版本,执行如下命令,将React更新到指定版本:npm install --save [email protected]
5、Navigator is deprecated and has been removed from this package. It can now be installed
- 原因是版本升级到0.43以上的话,Navigator不能直接从react-native里面获取了,需要添加额外的包:npm install react-native-deprecated-custom-components --save;并且跳转到指定的js文件中修改导入路径为:import {Navigator} from 'react-native-deprecated-custom-components';