Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Duplicate "graphql" modules #211

Closed
tobkle opened this issue Feb 18, 2018 · 12 comments
Closed

Error: Duplicate "graphql" modules #211

tobkle opened this issue Feb 18, 2018 · 12 comments

Comments

@tobkle
Copy link

tobkle commented Feb 18, 2018

After starting with today's version (there is no version tag):

yarn dev

And running a posts query in the playground, I received the following error:

Server is running on http://localhost:4000
Serving playground at http://localhost:3000/playground
Error: Cannot use GraphQLSchema "[object Object]" 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.

Solved it by

  • yarn clean cache
  • npm -rf node_modules
  • added in package.json the "resolutions" section
  • yarn install
{
  "name": "node-advanced",
  "scripts": {
    "start": "nodemon -e js,graphql -x node -r dotenv/config src/index.js",
    "debug": "nodemon -e js,graphql -x node --inspect -r dotenv/config src/index.js",
    "playground": "graphql playground",
    "dev": "npm-run-all --parallel start playground"
  },
  "dependencies": {
    "bcryptjs": "2.4.3",
    "graphql-yoga": "1.3.2",
    "jsonwebtoken": "8.1.1",
    "prisma-binding": "1.5.12"
  },
  "devDependencies": {
    "dotenv": "5.0.0",
    "graphql-cli": "2.14.1",
    "nodemon": "1.15.0",
    "npm-run-all": "4.1.2",
    "prisma": "1.2.4"
  },
  "resolutions": {
    "graphql": "^0.13.0",
    "**/graphql": "^0.13.0"
  }
}

Or is there a better way resolving this error situation?

@marktani
Copy link
Contributor

Gey @tobkle, thanks for reporting this issue!

Could you try following the steps mentioned in this comment?

Let me know if that doesn't solve the problem for you.

Thanks! 🙏

@SebaBoler
Copy link

first : yarn clean cache need be replace by yarn cache clean * Documentation Yarn
second: dont use npm -rf node_modules but rm -rf node_modules

@haysclark
Copy link

@tobkle It would be great if the "Answer" could be updated with the edits from @SebaBoler.

@AviIhej
Copy link

AviIhej commented Nov 10, 2018

I followed all of these steps and still got the same result. Any idea why?

@AliIsawi
Copy link

this solution worked for me :

  1. remove node_modules.
  2. remove package-lock.json
  3. run npm install again

that's it

@codemaster08240328
Copy link

@tobkle , I followed the step you mentioned, still have same issue.
Any idea why?
I added
"resolutions": {
"graphql": "^14.0.0",
"**/graphql": "^14.0.0"
},

@miketwo
Copy link

miketwo commented Mar 2, 2021

@codemaster08240328 If you search for graphql modules (npm ls graphql or yarn list --pattern graphql), are there duplicates with different versions? Where do they come from?

@lirenhao
Copy link

me too is '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.', exec 'npm ls graphql',result is 'npm ls graphql'

@marius-tafika
Copy link

yarn list graphql
example:
[email protected]
[email protected]

make all graphql to same version (see package.json)

@JoshuaAlzate
Copy link

I am encountering this error after I bundled my node application using webpack. I followed the resolution above yet the error persist.

This is my yarn list --pattern graphql

yarn list v1.22.17
├─ @apollographql/[email protected]
├─ @apollographql/[email protected]
├─ @graphql-tools/[email protected]
├─ @graphql-tools/[email protected]
├─ @graphql-tools/[email protected]
├─ @graphql-tools/[email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]

@ukesh-rajasekar
Copy link

@codemaster08240328 If you search for graphql modules (npm ls graphql or yarn list --pattern graphql), are there duplicates with different versions? Where do they come from?
This is the error msg when i tried to run codegen:

Error: Cannot use GraphQLScalarType "String" 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.

I tried @miketwo approach, worked in my case.

  1. yarn list --pattern graphql
  2. noticed I have multiple graphql modules
    something like this below
yarn list v1.22.17
├─ @apollographql/[email protected]
├─ @apollographql/[email protected]
├─ @apollographql/[email protected]
├─ @apollographql/[email protected]
├─ @apollographql/[email protected]
├─ @graphql-typed-document-node/[email protected]
├─ [email protected]
├─ [email protected]
│  └─ [email protected]
├─ [email protected]
│  ├─ [email protected]
│  └─ [email protected]
├─ [email protected]
└─ [email protected]
  1. Then made sure every graphql modules belongs to the same version (in my case it is 15.8.0)

@Zoli06
Copy link

Zoli06 commented Jun 25, 2022

I leave this comment to help others who did the same stupid mistake that I did. I have a folder structure like this:

project
├─ client
│  └─npm things
├─ server
│  └─npm things
└─npm things

I accidentally installed graphql in the project's root folder instead of the server folder. Even npm ls graphql didn't show that. Just removed it and the error has gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests