我发现graphql-js https://github.com/graphql/graphql-js库不允许依赖项也使用 graphql。
你会得到以下错误
Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results.
从下面的代码
const express = require('express');
const graphqlHTTP = require('express-graphql');
const { GraphQLSchema } = require('graphql');
// the module graphql-test-mod-obj-type' has
// graphql as a depenedency
const myType = require('graphql-test-mod-obj-type');
const app = express();
const schema = new GraphQLSchema({ query: myType })
app.use('/graphql', graphqlHTTP({
schema,
graphiql: true
}));
app.listen(4000);
我创建了一个小型存储库和一个小型公共 npm 包来演示这一点带有 npm-依赖于 graphql 的仓库 https://github.com/ghinks/graphql-test-consume-graphql-obj-type.git .
通过不将 graphql 模块作为模块中的依赖项,可以很容易地解决这个问题。但这肯定是一个问题吗?或者这是众所周知的事情?
我遇到了这个错误并使用以下步骤解决了它:
-
列出 graphql 包的所有可用实例以检查依赖性
npm ls graphql
-
删除node_modules目录
rm -rf 节点模块
-
删除 package-lock.json 文件
-
将“决议”对象添加到 package.json
“决议”:{
“graphql”:“15.5.0”,
“**/graphql”:“15.5.0”
}
-
添加预安装脚本以对 package.json 文件中的脚本对象强制执行解析选项
“预安装”:“npx npm-force-分辨率”
-
再次安装包
npm 安装
** 笔记***
就我而言,我还必须将节点版本从 v18.0 更改为 v17.0,因为我正在使用其他一些 apollo/federation 包,因此可能还要查看节点依赖项
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)