question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gatsby-source-graphql@2.2.1 throws error: Cannot use GraphQLDirective "@include" from another module or realm

See original GitHub issue

Description

While deploying a new site version where CI runs its own build for deployment, I am now running into a new error. When running gatsby develop, as it runs though plugin initialization, I am now getting the following error:

"gatsby-source-graphql" threw an error while running the sourceNodes lifecycle:

Cannot use GraphQLDirective "@include" 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.

  74 |     if (!sdl) {
  75 |       introspectionSchema = await introspectSchema(link);
> 76 |       sdl = printSchema(introspectionSchema);
     |             ^
  77 |     } else {
  78 |       introspectionSchema = buildSchema(sdl);
  79 |     }

File: node_modules/gatsby-source-graphql/gatsby-node.js:76:13

Which is followed by the following warning:

Error: Cannot use GraphQLDirective "@include" 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.

Previous to this, the project was running gatsby-source-graphql@2.1.33. Downgrade is however not fixing the issue.

Steps to reproduce

List of installed dependencies, updated from hello-world starter:

β”œβ”€β”€ @appbaseio/reactivesearch@3.7.1
β”œβ”€β”€ @aws-amplify/api@2.2.0
β”œβ”€β”€ @aws-amplify/auth@2.1.7
β”œβ”€β”€ @aws-amplify/pubsub@1.3.3
β”œβ”€β”€ @fortawesome/fontawesome-svg-core@1.2.28
β”œβ”€β”€ @fortawesome/free-brands-svg-icons@5.13.0
β”œβ”€β”€ @fortawesome/free-solid-svg-icons@5.13.0
β”œβ”€β”€ @fortawesome/pro-regular-svg-icons@5.13.0
β”œβ”€β”€ @fortawesome/react-fontawesome@0.1.9
β”œβ”€β”€ @tailwindcss/custom-forms@0.2.1
β”œβ”€β”€ gatsby@2.20.8
β”œβ”€β”€ gatsby-image@2.3.1
β”œβ”€β”€ gatsby-plugin-manifest@2.3.3
β”œβ”€β”€ gatsby-plugin-offline@3.1.2
β”œβ”€β”€ gatsby-plugin-postcss@2.2.1
β”œβ”€β”€ gatsby-plugin-react-helmet@3.2.1
β”œβ”€β”€ gatsby-plugin-sharp@2.5.3
β”œβ”€β”€ gatsby-source-filesystem@2.2.2
β”œβ”€β”€ gatsby-source-graphql@2.2.1
β”œβ”€β”€ gatsby-transformer-sharp@2.4.3
β”œβ”€β”€ prettier@2.0.2
β”œβ”€β”€ prop-types@15.7.2
β”œβ”€β”€ react@16.13.1
β”œβ”€β”€ react-dom@16.13.1
β”œβ”€β”€ react-headroom@3.0.0
β”œβ”€β”€ react-helmet@5.2.1
β”œβ”€β”€ tailwindcss@1.2.0
└── uuid@7.0.2

Configuration of plugin in gatsy-config.js:

{
      resolve: `gatsby-source-graphql`,
      options: {
        typeName: 'Book',
        fieldName: 'catalogue',
        url: 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
        headers: {
          'x-api-key': 'xxxxxx'
        }
      }
    }

Expected result

Previously, the plugin would run without issue and create the source nodes successfully

Actual result

When the plugin is initialized, it throws the error above.

Environment

  System:
    OS: macOS 10.15.3
    CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
    Shell: 5.8 - /usr/local/bin/zsh
  Binaries:
    Node: 10.19.0 - /usr/local/opt/node@10/bin/node
    npm: 6.13.4 - /usr/local/opt/node@10/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 80.0.3987.149
    Safari: 13.0.5
  npmPackages:
    gatsby: ^2.20.8 => 2.20.8 
    gatsby-image: ^2.3.1 => 2.3.1 
    gatsby-plugin-manifest: ^2.3.3 => 2.3.3 
    gatsby-plugin-offline: ^3.1.2 => 3.1.2 
    gatsby-plugin-postcss: ^2.2.1 => 2.2.1 
    gatsby-plugin-react-helmet: ^3.2.1 => 3.2.1 
    gatsby-plugin-sharp: ^2.5.3 => 2.5.3 
    gatsby-source-filesystem: ^2.2.2 => 2.2.2 
    gatsby-source-graphql: ^2.3.0 => 2.3.0 
    gatsby-transformer-sharp: ^2.4.3 => 2.4.3 
  npmGlobalPackages:
    gatsby-cli: 2.8.28

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ohlrcommented, Apr 26, 2020

I get the same error whith the following npm ls graphql

β”œβ”€β”¬ gatsby@2.20.36
β”‚ β”œβ”€β”¬ gatsby-cli@2.11.22
β”‚ β”‚ └─┬ gatsby-recipes@0.0.19
β”‚ β”‚   └── graphql@14.6.0  deduped
β”‚ └── graphql@14.6.0 
└─┬ gatsby-source-prismic-graphql@3.5.0
  β”œβ”€β”¬ gatsby-source-graphql@2.4.3
  β”‚ └── graphql@14.6.0  deduped
  └─┬ gatsby-source-graphql-universal@3.1.11
    └─┬ @types/graphql@14.5.0
      └── graphql@15.0.

resolved it with https://github.com/birkir/gatsby-source-graphql-universal/issues/14

0reactions
jaredh159commented, Jun 22, 2022

If you’re using npm 8.3.x or higher, you can now use:

"overrides": {
    "graphql": "14.6.0"
 }

…since npm doesn’t support resolutions

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Cannot use GraphQLObjectType "__Directive" from ...
Error : Cannot use GraphQLObjectType "__Directive" from another module or realm . Ensure that there is only one instance of "graphql" in theΒ ......
Read more >
Frequently Asked Questions - TypeGraphQL
Cannot use GraphQLSchema "[object Object]" from another module or realm. This error occurs mostly when there are more than one version of the...
Read more >
Cannot use GraphQLObjectType "__Directive" from another ...
I get this error: βœ– Cannot use GraphQLObjectType "__Directive" from another module or realm. Ensure that there is only one instance ofΒ ...
Read more >
graphql - UNPKG
34, throw new Error(`Cannot use ${className} "${stringifiedValue}" from another module or realm. 35. 36, Ensure that there is only one instance of "graphql"Β ......
Read more >
Error Cannot use GraphQLScalarType [*Type*] from another ...
I am trying to use apollo:codegen to generate schema and ... Error Cannot use GraphQLScalarType [*Type*] from another module or realm.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found