How to fix the annoying "Ensure there is only one instance of graphql" error

If you have been doing serious work with GraphQL over the last few years, you surely saw this error at one time or another:

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.

I personally tend to hit it in the worst possible times - think "Friday Night Hot Fix" situation. :-)
In this post I want to list some of the ways that I use to fix this problem.


First, take a look at the output of:
yarn why GraphQL

If you have different versions of GraphQL in the dependency tree try to make some updating/downgrading to make things match. This is the way to go if for example you realize you have one of your dependency very old - updating that might fix the problem.

If you can't get things to match exactly and you use fairly up-to-date dependencies add resolutions section to your package.json, like so:

"resolutions": {
 "graphql": "15.5.0"

Remove yarn.lock, reinstall dependencies.


Start with

npm dedupe

which should flatten the dependencies and if you have the same version of GraphQL dependency but in many places, this will take care of that.

If that does not help most probably you have different versions of GraphQL that can't be flattened.

npm ls graphql

can show you where are all the different dependencies coming from, try to do some updating/downgrading to make things match.

If that's not possible you can use npm-force-resolutions npm package to force the dependencies to use the same version of GraphQL.

"resolutions": {
  "graphql": "15.5.0"

to your package.json, and add a preinstall script:

scripts": {
  "preinstall":  "npx npm-force-resolutions"

Note: if you use npm 7 that won't work and your last bet is following instruction from this stackoverflow answer:

Let me know if you have any questions or thoughts in the comments below.

Let us help you on your journey to Quality Faster

We at specialize in helping our clients get more for less. We can get you to the holy grail of continuous deployment where every commit can go to production — and yes, even for large enterprises.

Feel free to schedule a call or send us a message below to see how we can help.

User icon
Envelope icon


Schedule a 30m call
  • For loops in JavaScript (vs _.times)

    From time to time I still see a for loop in JavaScript codebases. Linters are frequently angry about them. Let's see how we can replace them.

  • Sharing scalars between modules with Chimp

    Simplify your Chimp-based project even further with a new @predefined Scalar directive.

  • Adding TypeScript to the official Apollo Platform Tutorial app

    In todays video I go through a preparation of the official Apollo Platform Tutorial App for adding Chimp to it. I decided to divide that task into two steps - first is adding TypeScript to the codebase. Watch me work, struggle, fly through code, hopefully you will learn some tricks :)