从git新down的代码 npm install 安装依赖,react-native run-android后服务启动100%无任何错误,可app启动后爆红了react native can't find variable: self,
1、按理说can't find variable:*是因为缺少某种引用,沿着这个思路去解决发现self没有用的地方,好吧百度
2、普遍说的是修改node_modules/isomorphic-fetch/fetch-npm-browserify.js文件为
var globalObject = typeof self === "undefined" ? global : self;
module.exports = globalObject.fetch.bind(globalObject);
//module.exports = fetch;
经测试问题依旧
3、在stackoverflow上无意间看到这样一篇文章https://stackoverflow.com/questions/52269560/react-native-expo-cant-find-variable-self/52271297#52271297
For users creating new project with expo-cli or XDE, you will get red screen “Can’t Find Variable Self” after your first “yarn” or “npm install”. This is because of new “whatwg-fetch” 3.0.0 published yesterday (https://www.npmjs.com/package/whatwg-fetch 23). So you just need to force dependency to previous version: "whatwg-fetch": "^2.0.4" It means put it in package.json as “dependency”. Manually, with “yarn add whatwg-fetch@2.0.4.” Or with “npm add whatwg-fetch@2.0.4”.
修改版本号2.0.4 成功进入应用 ,哎... 原来是whatwg-fetch3.0.0搞得鬼
thinks: