react-native - 无法从“node_modules/graphql/validation/index.js”解析“./rules/FieldsOnCorrectType”
问题描述
我正在使用 apollo 客户端 3 构建一个反应本机应用程序,并在生成 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
文件中的下一次导入时出错......我不明白为什么。
解决方案
升级到 apollo 客户端 3 后,我在使用 react native 应用程序时遇到了同样的问题。对我来说,这是一个 react native 缓存问题,在按照以下说明清除缓存后问题就消失了:如何清除 react-native 缓存?.
我正在使用 react native cli 并使用了这些命令(我没有检查它们是否真的需要):
watchman watch-del-all
rm -rf /tmp/metro-cache
rm -rf node_modules
npm cache clean --force
npm install
npm start -- --reset-cache
如果您使用的是 expo cli,那么显然您可以这样做:
expo start -c
推荐阅读
- python - 使用python根据匹配键修剪json
- java - java中的同步方法不能像indended那样工作
- flutter - 如何在导轨宽度最小的情况下在 NavigationRail 图标之间创建更多垂直空间?
- bind - 为什么回调堆栈大小超出我使用的绑定语法?
- mongodb - 查询使用特定资产的每个平均值的计数来查找存储在 mongodb 中的平均值的平均值
- python - 如何将输入链接到对象的属性并在单击时更新该属性?
- python - 如何比较 DataFrame 中的多行并编辑 ID 匹配的某些值
- scala - Scala Compiler Plugin - 确定方法是否被覆盖
- vue.js - VueJS:如何从 vuex 存储中获取嵌套对象值?
- objective-c - 从选择器调用函数指针