Getting multiple instances of graphql error despite only having a single version
Problem
I wasn't sure whether or not to make a new issue or comment on https://github.com/graphql/graphql-js/issues/594 but that one is so old I figured it would be preferable to start anew In my project I get the "ensure that there are not multiple versions of GraphQL installed in your node_modules directory" error despite having done so. yarn list output: [code block] and for posterity: [code block] My tech stack includes apollo-server-lambda and nexus-schema. Not sure if/how one of them could be behind this, but the issue only cropped up after switching from apollo-server-express to apollo-server-lambda. Nevertheless, it would seem that graphql-js is reporting this error erroneously as I have proven there is only one instance of graphql in my node_modules directory. exact error message: [code block] Link to my project repo: https://github.com/link2cory/portfolio-backend/tree/serverless a quick note: although it is not in the current version of my repo, I have tried making use of the resolutions yarn with exactly the same results. Plus the evidence I have provided above suggests to me that it should not be necessary based on my project dependencies. Please correct me if I am wrong in any of these assumptions!
Error Output
error despite having done so.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Resolve GraphQL Multiple Versions Error in Apollo Server Lambda
The error 'ensure that there are not multiple versions of GraphQL installed in your node_modules directory' can occur due to transitive dependencies that pull in different versions of the GraphQL package. This is common when switching between different Apollo Server implementations, as they may have different dependency requirements. Even if `yarn list` shows only one version, some packages may still reference a different version in their lock files or require a specific version that conflicts with the installed version.
Awaiting Verification
Be the first to verify this fix
- 1
Check for Duplicate GraphQL Versions
Run the following command to check for any duplicate versions of GraphQL in your project. This will help identify if any dependencies are pulling in different versions.
bashyarn list graphql - 2
Use Yarn Resolutions
If you find multiple versions of GraphQL, add a resolutions field in your package.json to force all dependencies to use the same version. This ensures consistency across your project.
json{ "resolutions": { "graphql": "15.5.0" } } - 3
Clear Yarn Cache
Sometimes, cached versions can cause issues. Clear the Yarn cache to ensure that all packages are fetched fresh. Run the following command:
bashyarn cache clean - 4
Reinstall Node Modules
After clearing the cache, delete the node_modules directory and reinstall the dependencies to ensure that the resolutions are applied correctly.
bashrm -rf node_modules && yarn install - 5
Verify Dependency Tree
After reinstalling, run the yarn list command again to verify that only one version of GraphQL is installed. This confirms that the resolutions have taken effect.
bashyarn list graphql
Validation
To confirm the fix worked, run your application and ensure that the GraphQL error no longer appears. Additionally, check the output of 'yarn list graphql' to verify that only one version is present.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep