Anyone getting this error below for using "graphql-yoga": "^1.18.3" in your package.json. I have nothing else but only graphql-yoga in my dependencies but the server isn't running. The error message:
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.
Code:
// index.js
const { GraphQLServer } = require('graphql-yoga')
const typeDefs = `
type Query {
hello(name: String): String!
}
`
const resolvers = {
Query: {
hello: (_, { name }) => `Hello ${name || 'World'}`,
},
}
const server = new GraphQLServer({ typeDefs, resolvers })
server.start(() => console.log('Server is running on localhost:4000'))
Any ideas how to get this fixed?
I face the same issue.
Add a resolutions field to your package.json file and define your version overrides:
"resolutions":{
"graphql": "^15.0.0"
}
I have this in my package.json
"dependencies": {
"@babel/polyfill": "^7.11.5",
"@graphql-tools/graphql-file-loader": "^6.2.2",
"@graphql-tools/load": "^6.2.2",
"babel-cli": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"bcryptjs": "^2.4.3",
"compression": "^1.7.4",
"env-cmd": "^10.1.0",
"express": "^4.17.1",
"express-sslify": "^1.2.0",
"graphql-cli": "^4.0.0",
"graphql-yoga": "^1.18.3",
"jsonwebtoken": "^8.5.1",
"prisma-binding": "^2.3.16"
},
"devDependencies": {
"concurrently": "^5.3.0",
"nodemon": "^2.0.4"
},
"resolutions": {
"graphql": "^15.0.0"
}
still give me this error when i run any query or mutation from the server playground
Error: Cannot use GraphQLNonNull "User!" 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.
at instanceOf (D:\00. DEVELOPMENT\FULL PROJECTS\social-template\node_modules\graphql-binding\node_modules\graphql\jsutils\instanceOf.js:28:13)
at isNonNullType (D:\00. DEVELOPMENT\FULL PROJECTS\social-template\node_modules\graphql-binding\node_modules\graphql\type\definition.js:194:34)
at isWrappingType (D:\00. DEVELOPMENT\FULL PROJECTS\social-template\node_modules\graphql-binding\node_modules\graphql\type\definition.js:364:30)
at Object.getNamedType (D:\00. DEVELOPMENT\FULL PROJECTS\social-template\node_modules\graphql-binding\node_modules\graphql\type\definition.js:423:12)
at buildInfoForAllScalars (D:\00. DEVELOPMENT\FULL PROJECTS\social-template\node_modules\graphql-binding\src\info.ts:48:21)
at Object.buildInfo (D:\00. DEVELOPMENT\FULL PROJECTS\social-template\node_modules\graphql-binding\src\info.ts:31:12)
at Prisma.Delegate.delegateToSchema (D:\00. DEVELOPMENT\FULL PROJECTS\social-template\node_modules\graphql-binding\src\Delegate.ts:159:18)
at Prisma.<anonymous> (D:\00. DEVELOPMENT\FULL PROJECTS\social-template\node_modules\graphql-binding\src\Delegate.ts:65:17)
at step (D:\00. DEVELOPMENT\FULL PROJECTS\social-template\node_modules\graphql-binding\dist\Delegate.js:32:23)
at Object.next (D:\00. DEVELOPMENT\FULL PROJECTS\social-template\node_modules\graphql-binding\dist\Delegate.js:13:53)
Fix works on my side:
add resolutions field in package.json
use yarn install
Most helpful comment