apollo-tooling icon indicating copy to clipboard operation
apollo-tooling copied to clipboard

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

Open chenrui333 opened this issue 3 years ago • 66 comments

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

chenrui333 avatar Aug 12 '21 20:08 chenrui333

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

ralexandr avatar Aug 12 '21 20:08 ralexandr

I tried going all the way back to 2.20.0 just for kicks and it's broken with the same error:

    "graphql-download": "npx [email protected] schema:download --endpoint=https://..../graphql schema.json",

I thought using npx with a pinned version would mean "this should never break", but I guess not?

stephenh avatar Aug 12 '21 20:08 stephenh

I am having the same issue--downgrading does not help.

andrewlague avatar Aug 12 '21 21:08 andrewlague

I tried going all the way back to 2.20.0 just for kicks and it's broken with the same error:

    "graphql-download": "npx [email protected] schema:download --endpoint=https://..../graphql schema.json",

I thought using npx with a pinned version would mean "this should never break", but I guess not?

I believe there's no package-lock.json so it'll just get the latest ... and break. I'm broken too as of 2+ hours ago on v2.22.0

john-twigg-ck avatar Aug 12 '21 21:08 john-twigg-ck

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

@ralexandr @andrewlague @stephenh How did you downgrade?

matijs avatar Aug 13 '21 07:08 matijs

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

@ralexandr @andrewlague @stephenh How did you downgrade?

npm i -D [email protected] and then npm run apollo:push:dev (i have "scripts": { "apollo:push:dev": "env-cmd --silent -f ./.env apollo service:push --variant=development", ... } inside my package.json)

ralexandr avatar Aug 13 '21 07:08 ralexandr

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

Effanuel avatar Aug 13 '21 10:08 Effanuel

@Effanuel did you use npm i -g [email protected] to pin it or your package.json file? I still can't seem to get it to work.

andrewlague avatar Aug 13 '21 16:08 andrewlague

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

jedsada-gh avatar Aug 13 '21 16:08 jedsada-gh

@Effanuel did you use npm i -g [email protected] to pin it or your package.json file? I still can't seem to get it to work.

Just add apollo with a veraion to devdeps

Effanuel avatar Aug 13 '21 18:08 Effanuel

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

ralexandr avatar Aug 17 '21 17:08 ralexandr

@Effanuel did you use npm i -g [email protected] 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",

mikecousins avatar Aug 17 '21 23:08 mikecousins

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?

liamross avatar Aug 27 '21 01:08 liamross

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.

LouGhys avatar Aug 27 '21 09:08 LouGhys

This issue is caused by apollo-language-server requiring @apollo/[email protected] but @apollo/[email protected] 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 [email protected] 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 [email protected] (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.

WIStudent avatar Aug 30 '21 10:08 WIStudent

Any updates on this?

viktorstrate avatar Sep 11 '21 12:09 viktorstrate

For us, downgrading to "2.33.4" (no need for "apollo-language-server) was enough to restore functionality. Still unclear though

mccxiv avatar Sep 15 '21 03:09 mccxiv

I'm having the same issue I tried to use npx to use the latest then tried with 2.33.4 and also 2.20.0 and neither of them worked.

npx [email protected] schema:download --endpoint=https://graphql-pokeapi.graphcdn.app/graphql schema.json
Error: Cannot find module 'graphql/validation/rules/KnownArgumentNamesRule'
Require stack:
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/@apollo/federation/dist/composition/validate/preNormalization/tagDirective.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/@apollo/federation/dist/composition/validate/preNormalization/index.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/@apollo/federation/dist/composition/validate/index.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/@apollo/federation/dist/composition/composeAndValidate.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/@apollo/federation/dist/composition/index.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/@apollo/federation/dist/index.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/apollo-language-server/lib/providers/schema/file.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/apollo-language-server/lib/providers/schema/index.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/apollo-language-server/lib/project/base.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/apollo-language-server/lib/index.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/apollo/lib/Command.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/apollo/lib/commands/service/download.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/@oclif/config/lib/plugin.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/@oclif/config/lib/config.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/@oclif/config/lib/index.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/@oclif/command/lib/command.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/@oclif/command/lib/index.js
- C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/apollo/bin/run
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
    at Function.Module._load (node:internal/modules/cjs/loader:774:27)
    at Module.require (node:internal/modules/cjs/loader:1013:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (C:/Users/joaof/AppData/Local/npm-cache/_npx/4f744a7352cbb6ab/node_modules/@apollo/federation/dist/composition/validate/preNormalization/tagDirective.js:6:34)
    at Module._compile (node:internal/modules/cjs/loader:1109:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
    at Module.load (node:internal/modules/cjs/loader:989:32)
    at Function.Module._load (node:internal/modules/cjs/loader:829:14)
    at Module.require (node:internal/modules/cjs/loader:1013:19)

joaopedrodcf avatar Sep 18 '21 09:09 joaopedrodcf

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 🙏

joaopedrodcf avatar Sep 18 '21 10:09 joaopedrodcf

I've tried all of the above and this is still not working for me. Node is version 14.17.4, installed apollo globally at version 2.33.4, pinned Apollo in the app at the same version and "apollo-language-server": "1.26.3",

kierangillen avatar Sep 22 '21 15:09 kierangillen

Having this issue all of a sudden as well. Tried pinning apollo and apollo-language-server as specified above but no luck.

c0bra avatar Sep 22 '21 15:09 c0bra

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

liamross avatar Sep 28 '21 23:09 liamross

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"

cblaettl avatar Sep 29 '21 13:09 cblaettl

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

sergpetrov avatar Oct 01 '21 10:10 sergpetrov

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.

tylermmorton avatar Oct 10 '21 21:10 tylermmorton

How is this not getting more traction?

mikecousins avatar Oct 22 '21 15:10 mikecousins

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):

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.

adamshaylor avatar Oct 28 '21 15:10 adamshaylor

I solved putting "graphql" in peerDependencies in package.json

OuthBack avatar Nov 08 '21 10:11 OuthBack

@OuthBack do you mind giving more contexto to how you solved this issue? thanks :D

stephichau avatar Nov 08 '21 19:11 stephichau

@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.

OuthBack avatar Nov 09 '21 10:11 OuthBack