【发布时间】:2021-02-23 02:29:56
【问题描述】:
我正在使用 apollo 客户端 3 构建一个 react 本机应用程序,并在生成 javascript 包时不断收到以下错误。
Failed building JavaScript bundle.
Unable to resolve "./rules/FieldsOnCorrectType" from "node_modules/graphql/validation/index.js"
我的代码很简单,这是App.tsx:
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import useCachedResources from './hooks/useCachedResources';
import useColorScheme from './hooks/useColorScheme';
import Navigation from './navigation';
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
const client = new ApolloClient({
uri: 'localhost:4000/graphql',
cache: new InMemoryCache()
});
export default function App() {
const isLoadingComplete = useCachedResources();
const colorScheme = useColorScheme();
if (!isLoadingComplete) {
return null;
} else {
return (
<ApolloProvider client={client}>
<SafeAreaProvider>
<Navigation colorScheme={colorScheme} />
<StatusBar />
</SafeAreaProvider>
</ApolloProvider>
);
}
}
我已将其追溯到新 ApolloClient 对象的实例化 - 注释掉这些行(和提供程序)会导致错误消失。
将node_modules/graphql/validation/rules/FieldsOnCorrectTypeRule.js 重命名为node_modules/graphql/validation/rules/FieldsOnCorrectType.js(删除文件名的Rule 后缀)修复了该特定错误,但随后在validation/index.js 文件中的下一次导入时出现错误...我不明白为什么。
【问题讨论】:
标签: react-native expo apollo-client