Nir*_*ngi 5 node.js react-native isomorphic-fetch-api
isomorphic-fetch在React Native应用程序中添加节点模块(版本:^ 2.2.1)后,我收到错误Can't find variable: self.
这里我附上了截图.
从位于node_modules> isomorphic-fetch>的文件中抛出错误fetch-npm-browserify.js.
以下是该文件的代码.
// 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);
Run Code Online (Sandbox Code Playgroud)
小智 6
@Nirav Dangi,按新建fetch-npm-react-native.js的方式在我的项目里面没有起作用;我这边处理方式,是直接修改,node_modules> isomorphic-fetch> fetch-npm-browserify.js文件的返回:
谷歌翻译:@Nirav Dangi,按照我的项目中的新方式fetch-npm-react-native.js无法正常工作; 我在这里处理直接更改,node_modules> isomorphic-fetch> fetch-npm-browserify.js文件返回:
var globalObject = typeof self === "undefined" ? global : self;
module.exports = globalObject.fetch.bind(globalObject);
//module.exports = fetch;
Run Code Online (Sandbox Code Playgroud)
我在这个答案的帮助下解决了这个问题,
https://github.com/matthew-andrews/isomorphic-fetch/pull/80
为 React Native 指定一个单独的入口点,导出 React Native 的 fetch() polyfill。
fetch-npm-react-native.js。将此文件拖放到该node_modules > isomorphic-fetch位置。module.exports = fetch;到 fetch-npm-react-native.js 文件中。node_modules > isomorphic-fetch > package.json。在package.json文件中,添加"main": "fetch-npm-node.js",代码行。npm install
当然这要归功于Jou
| 归档时间: |
|
| 查看次数: |
4942 次 |
| 最近记录: |