我处理这个问题已经大约两周了。 起初,它根本不起作用。在花了几天时间寻找解决方案后,我可以通过将这些代码行添加到我的 index.js 文件中来修复它。
XMLHttpRequest = GLOBAL.originalXMLHttpRequest ?
GLOBAL.originalXMLHttpRequest :
GLOBAL.XMLHttpRequest;
global.Blob = null
之后在开发模式下运行良好,一切正常。 但当我发布我的应用程序时,我意识到它在发布版本中不起作用!
我有点确定这是 apollo 在幕后使用的 fetch API 的问题。但我不知道该怎么做才能解决它。
我还尝试运行一个新项目并将我的代码粘贴到其上,但没有成功。
这是我的 apollo 客户端代码:
import ApolloClient from 'apollo-client'
import Statics from './statics'
import {HttpLink} from 'apollo-link-http'
import { InMemoryCache } from '@apollo/client';
const customFetch = (uri, options) => {
return fetch(uri, options)
.then(response => {
if (response.status >= 500) { // or handle 400 errors
return Promise.reject(response.status);
}
return response;
});
};
export const client = new ApolloClient({
link: new HttpLink({uri:`${Statics.baseUrl}/graphql`, fetch:customFetch}) ,
cache: new InMemoryCache(),
});
尝试使用
isomorphic-fetch
代替 fetch