Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Error - Can't find variable: self

After adding a node module,isomorphic-fetch(version : ^2.2.1) in React Native app, I am getting an error of Can't find variable: self.
Here I have attached a screenshot.

enter image description here

The error is thrown from the file, located at node_modules > isomorphic-fetch > fetch-npm-browserify.js.
Following is the code of that file.

// the whatwg-fetch polyfill installs the fetch() function
// on the global object (window or self)
//
// Return that as the export for use in Webpack, Browserify etc.
require('whatwg-fetch');
module.exports = self.fetch.bind(self);
like image 233
Nirav Dangi Avatar asked May 31 '16 11:05

Nirav Dangi


1 Answers

@Nirav Dangi,按新建fetch-npm-react-native.js 的方式在我的项目里面没有起作用; 我这边处理方式,是直接修改,node_modules > isomorphic-fetch > fetch-npm-browserify.js 文件的返回:

Google Translate: @Nirav Dangi, in accordance with the new way fetch-npm-react-native.js in my project which is not working; I am here to deal with direct changes, node_modules> isomorphic-fetch> fetch-npm-browserify.js file Back:

var globalObject = typeof self === "undefined" ? global : self;
module.exports = globalObject.fetch.bind(globalObject);
//module.exports = fetch;
like image 152
galaxybing Avatar answered Oct 05 '22 23:10

galaxybing