Error: Cannot use GraphQLSchema "[object GraphQLSchema]" from another module or realm.
Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed.
https://yarnpkg.com/en/docs/selective-version-resolutions
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.
When working in a monorepo and importing a graphql schema from a submodule made with makeExecutableSchema in another submodule
.
โโโ ...
โโโ packages
โ โโโ bar
โ โ โโโ package.json
โ โ # "apollo-server": "^2.10.0"
โ โโโ foo
โ โ โโโ package.json
โ โ # "apollo-server": "^2.10.0"
โ โ # "foo": "file:../foo"
โ โโโ ...
โโโ ...
repository: https://github.com/Sceat/graphql-dependency-duplication
I guess @types/graphql-upload is breaking submodules by forcing a Graphql dependency, it should be a dev dependency on apollo-server-core, or DefinitelyTyped should use graphql as a peerDependency
as a quick workaround we can install graphql globally and link in every submodule
npm i -g graphql
npm link graphql # in /bar and /foo
I meet the same issue when using webpack
"dependencies": {
"apollo-server": "^2.18.2",
"babel-loader": "^8.1.0",
"graphql": "^15.3.0",
"node-loader": "^1.0.0",
"webpack": "^5.0.0",
"webpack-node-externals": "^2.5.0"
},
//webpack
mode: "development",
target: "node",
module: {
rules: [
{
test: /\.(j|t)sx?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
cacheDirectory: false
},
},
}
],
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"],
},
npm link graphql doesnt work for me,
bash > npm ls graphql
โโโฌ [email protected]
โ โโโฌ [email protected]
โ โโโฌ @types/[email protected]
โ โโโ [email protected] deduped
โโโ [email protected]
Refer the workaround #4637
Most helpful comment
as a quick workaround we can install graphql globally and link in every submodule