apollo-tooling: cannot find module error for apollo-cli 2.33.{6,7,8,9}

When I was trying to upgrade the formula to use the latest 2.33.6 release, it looks like the apollo command does not work anymore.

$ /usr/local/Cellar/apollo-cli/2.33.6/bin/apollo client:check
    Error: Cannot find module
    'graphql/validation/rules/KnownArgumentNamesRule'
    Require stack:
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /node_modules/@apollo/federation/dist/composition/validate/preNormali
    zation/tagDirective.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /node_modules/@apollo/federation/dist/composition/validate/preNormali
    zation/index.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /node_modules/@apollo/federation/dist/composition/validate/index.js
    -
    /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo/n
    ode_modules/@apollo/federation/dist/composition/composeAndValidate.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /node_modules/@apollo/federation/dist/composition/index.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /node_modules/@apollo/federation/dist/index.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /node_modules/apollo-language-server/lib/providers/schema/file.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /node_modules/apollo-language-server/lib/providers/schema/index.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /node_modules/apollo-language-server/lib/project/base.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /node_modules/apollo-language-server/lib/index.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /lib/Command.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /lib/commands/client/check.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /node_modules/@oclif/config/lib/plugin.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /node_modules/@oclif/config/lib/config.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /node_modules/@oclif/config/lib/index.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /node_modules/@oclif/command/lib/command.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /node_modules/@oclif/command/lib/index.js
    - /usr/local/Cellar/apollo-cli/2.33.6/libexec/lib/node_modules/apollo
    /bin/run
    Code: MODULE_NOT_FOUND

relates to https://github.com/Homebrew/homebrew-core/pull/83152

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 64
  • Comments: 65 (1 by maintainers)

Commits related to this issue

Most upvoted comments

This issue is still a problem. It gave me 12-hours of pain. Nothing in this thread solved it for me although the information and context were very useful.

These pinned devDependencies worked for me:

"apollo": "2.33.4",
"apollo-codegen-core": "0.40.3",
"apollo-language-server": "1.26.3",

I had the same issue with our CI workflow and the downgrading didn’t help. But installing graphql helps npm install -g graphql

What a Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega Mega BUG

WOW. Please someone from Apollo fix this! (Almost 1 year later).

Is there any solution except downgrading nodejs and/or npm’s and/or apollo’s versions ?

Which will happen first: this gets fixed, or George R.R. Martin releases his next GoT book?

I have the same error as the screenshot on environment node v16.6.2. When I downgrade node to v14.17.5 (npm v6.14.14) and re-install it’s worked for me.

Screen Shot 2564-08-13 at 11 51 34 PM

Guys the solution for this is that you need to check the version of your graphql that is compatible with your apollo. For example: i had the graphql version 14.5.8 and my apollo version was 2.33.9. These are not compatible. I had to check in my node_modules the folder for apollo, check the package.json ((you should see something like this “graphql”: “14.0.2 - 14.2.0 || ^14.3.1 || ^15.0.0”)) and wich versions are compatible with the version that i current had. In this case i just update it to graphql 15.8.0. And it works

This issue is caused by apollo-language-server requiring @apollo/federation@0.27.0 but @apollo/federation@0.27.0 no longer working with graphql@14 (see https://github.com/apollographql/federation/issues/904). @apollo/federation corrected this issue in 0.27.1 by requiring graphql@15.4 or higher as peer dependency, dropping the support for graphql@14.

There are 2 options to fix this issue here:

  • Either downgrade @apollo/federation inside apollo-language-server to a version that still works with graphql@14
  • Or make all apollo-tooling packages fully compatible with graphql@15.4 (currently they are not, see e.g. https://github.com/apollographql/apollo-tooling/issues/2232) and drop support for any graphql version lower than 15.4.

This issue is still a problem. It gave me 12-hours of pain. Nothing in this thread solved it for me although the information and context were very useful.

These pinned devDependencies worked for me:

"apollo": "2.33.4",
"apollo-codegen-core": "0.40.3",
"apollo-language-server": "1.26.3",

@LukeAvsec-DarwinHomes Thank you so much. Was trying to fix versions for a long time, couldn’t find the right one till now!

How is this not getting more traction?

@Effanuel did you use npm i -g apollo-language-server@1.26.3 to pin it or your package.json file? I still can’t seem to get it to work.

package.json:

    "apollo": "2.33.4",
    "apollo-language-server": "1.26.3",

@LukeAvsec-DarwinHomes man you are a life saver

I’ve added the following postinstall script to the scripts section of my package.json and it work for me and my co-worker:

"postinstall": "rm -r node_modules/apollo-language-server/node_modules/graphql"

Okay made it work guys, using the latest version of the package but using node 14.16.0:

npx apollo schema:download --endpoint=https://graphql-pokeapi.graphcdn.app/graphql schema.json

The moment I changed node version with nvm everything worked 🙏

Pinning apollo to 2.33.4 and apollo-language-server to 1.26.3 worked for me

Thanks for the above…the following worked for me…

RUN npm install -g apollo@2.34.0 graphql@16.6.0

running from Docker

FROM node:16.17.0
RUN npm install -g npm@8.15.0

@stephichau I was in my project using node v16.13.0, NPM v8.1.0, graphql v16.0.1 and apollo v2.33.8. It was giving me this same error, so I put graphql in peerDependencies, removed node_modules and installed again. But in another project this approch didn’t work. The node, npm, graphql and apollo versions are old and cannot update them. So I installed graphql and apollo globally, because I just needed the schema file.

Hi, we were stuck on this and was blocking us.

This is what worked for us:

  • Pinned apollo to 2.33.4 (version before it broke) Then we kept having the “duplicate graphql” warning when running, so we:
  • deleted node_modules
  • deleted package-lock.json
  • installed with “yarn” instead of “npm install”

Switching to yarn worked for us somehow, hope this can help.

Met same issue, but downgrading to 2.33.4 didn’t help

A super hacky way to run apollo@2 schema:download using npx today:

  1. Run npx apollo@2 schema:download and observe the path in the error
    • e.g. /Users/foobar/.npm/_npx/XXXXXXXXXXXXXXXX
  2. Switch to this directory and install specific versions of packages
    • cd /Users/foobar/.npm/_npx/XXXXXXXXXXXXXXXX
    • npm install apollo@2.33.4 apollo-codegen-core@0.40.3 apollo-language-server@1.26.3
  3. npx apollo@2 schema:download should now work 🎉

Thank you @sergpetrov your solution to install graphql globally worked perfectly for me too npm install -g graphql

Consider using the Rover CLI instead of a deprecated tool.

Rover CLI doesn’t support codegen yet

installing apollo globally and then running the codegen worked for me

npm i -g apollo
apollo -v
apollo/2.33.10 win32-x64 node-v16.14.2
apollo service:download --endpoint=ENDPOINT graphql-schema.json

running the apollo service through a package.json script stil doesn’t work

it worked!! it worked!! thanks @LukeAvsec-DarwinHomes

What worked for me on a mac:

brew install node@16
yarn global add apollo

@traviscollins for us @LukeAvsec-DarwinHomes solution is not working with node v16.13.1 but v12.18.4.

If you’re using Node 16, see @LukeAvsec-DarwinHomes’s solution above.

We wanted to be able to run apollo client:codegen as an npm script to update our TypeScript types. This turned out to be kind of awkward because we’d followed vue-apollo’s instructions and had already indirectly installed Apollo’s sub-dependencies via apollo-boost. We did manage to get the CLI to work for a few months with the following combination of explicit dependencies (dev and otherwise):

  • apollo-boost@0.4.9 (for base vue-apollo installation)
  • graphql@15.5.0 (for base vue-apollo installation)
  • vue-apollo@3.0.7
  • apollo-utilities@1.3.4 (added later to configure the in-memory cache)
  • apollo@2.33.6 (for the codegen CLI)

Then, about a week ago, we had to reinitialize our package-lock.json (for reasons I’ll not get into here) and came across the same error as in this ticket (Cannot find module 'graphql/validation/rules/KnownArgumentNamesRule'). @WIStudent does an excellent root cause analysis in their comment above. No combination of downgrades resolved the error.

Our workaround was to uninstall our apollo dependency and change our npm scripts to use npx apollo client:codegen instead. Of course, npx has to install all the dependencies it needs at runtime, but they do at least resolve to a combination of dependencies that work.

On Node v16.8.0, when I try to pin by adding versions to package.json (I’m in a monorepo, this has been added to the root package.json), I get the following error:

CLIError: Error in "Loading schema for core": Error: Cannot use GraphQLSchema "[object GraphQLSchema]" 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.

This may be specific to my case, but it results in this fix not working for me (everything worked as of a week ago, and nothing in my code has changed). Presumably this is an internal dependency issue within Apollo?

Rover CLI doesn’t support codegen yet

From what I understand it isn’t going to. Apollo recommends graphql-code-generator but I believe it doesn’t cover quite every use case.

anybody tried this on an arm64/M1? solutions from above didn’t work for me.

Consider using the Rover CLI instead of a deprecated tool.

anybody tried this on an arm64/M1? solutions from above didn’t work for me.

@traviscollins for us @LukeAvsec-DarwinHomes solution is not working with node v16.13.1 but v12.18.4.

fwiw @LukeAvsec-DarwinHomes 's solution is working for me w/ node v16.14.1 (using graphql ^14.7.0)

I’m running into this issue as well, posting for notifications and updates 👍 I was following this tutorial on a fresh project. https://www.apollographql.com/blog/tooling/apollo-codegen/typescript-graphql-code-generator-generate-graphql-types/

Locking the versions and installing graphql did not help.

Got tired of waiting and the proposed fixes didn’t work for me, so I switched to graphql-code-generator.

Differences:

  • generates the code all in one file instead of different files (not really a pro or con)
  • generates all the hooks for you which is actually unreal (definitely a pro, makes the hooks so much smaller without plugging in all the generics manually)

Edit: I think I’ve got a good configuration now: I’ve moved the gql tag stuff into something.gql files, pointed the apollo.config.js file to only include those files (so I don’t lose VSCode Apollo app autocompletion etc), and running graphql-code-generator on those to generate the TypeScript hooks