npm react-native-fetch-blob – “RNFetchBlob.fetch不是函数”

我正在使用npm包react-native-fetch-blob 。
我已经遵循了git仓库中的所有步骤来使用这个包。

然后我使用下面这行导入了这个包:

var RNFetchBlob = require('react-native-fetch-blob'); 

我正试图请求一个包含从服务器的图像的BLOB。

这是我的主要方法。

 fetchAttachment: function(attachment_uri) { var authToken = 'youWillNeverGetThis!' var deviceId = '123'; var xAuthToken = deviceId+'#'+authToken //Authorization : 'Bearer access-token...', // send http request in a new thread (using native code) RNFetchBlob.fetch('GET', config.apiRoot+'/app/'+attachment_uri, { 'Origin': 'http://10.0.1.23:8081', 'X-AuthToken': xAuthToken }) // when response status code is 200 .then((res) => { // the conversion is done in native code let base64Str = res.base64() // the following conversions are done in js, it's SYNC let text = res.text() let json = res.json() }) // Status code is not 200 .catch((errorMessage, statusCode) => { // error handling }); } 

我不断收到以下错误:

“可能未处理的Promise Refection(id:0):TypeError:RNFetchBlob.fetch不是函数”。

有任何想法吗?

问题在于,您正在使用针对ES6 / ES2015编写的库的ES5样式require语句。 你有两个select:

ES5:

 var RNFetchBlob = require('react-native-fetch-blob').default 

ES6:

 import RNFetchBlob from 'react-native-fetch-blob'