Multiple MobX instances in your application

使用react-native-router-flux结合mobx开发报错Multiple MobX instances in your application

原因应该是react-native-router-flux中集成了mobx,然后在自己项目里面安装mobx的时候,导致有多个mobx存在,解决办法
删掉dependencies中的mobx

"dependencies": {
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "jcore-react-native": "^1.2.5",
    "jpush-react-native": "^2.2.1",
    "react": "16.0.0",
    "react-native": "0.51.0",
    "react-native-device-info": "^0.21.5",
    "react-native-router-flux": "^4.0.0-beta.28",
    "react-native-sms-verifycode": "^1.1.6",
    "react-native-splash-screen": "^3.0.6",
    "react-native-uuid": "^1.4.9",
    "react-navigation": "1.0.0-beta.21",
    "safe-buffer": "^5.1.1",
    "teaset": "^0.5.6"
  },

新加

 "peerDependencies": {
    "mobx": "^4.x",
    "mobx-react": "^5.x"
  },

peerDependencies可用来解决当我们的模块需要某个依赖,但是这个依赖如果写入dependencies,而引用我们这个模块的项目也有这个依赖,那么就可能造成依赖被安装两次,结果在nodejs中require的时候引用到不同模块而造成bug。

你可能感兴趣的:(Multiple MobX instances in your application)