apollographql / apollo-tooling

✏️ Apollo CLI for client tooling (Mostly replaced by Rover)
https://apollographql.com
MIT License
3.04k stars 468 forks source link

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

Open chenrui333 opened 3 years ago

chenrui333 commented 3 years ago

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

ralexandr commented 3 years ago

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

stephenh commented 3 years ago

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 apollo@2.20.0 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?

andrewlague commented 3 years ago

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

john-twigg-ck commented 3 years ago

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 apollo@2.20.0 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

matijs commented 3 years ago

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

@ralexandr @andrewlague @stephenh How did you downgrade?

ralexandr commented 3 years ago

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

@ralexandr @andrewlague @stephenh How did you downgrade?

npm i -D apollo@2.33.4 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)

Effanuel commented 3 years ago

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

andrewlague commented 3 years ago

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

jedsada-gh commented 3 years ago

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

Effanuel commented 3 years ago

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

Just add apollo with a veraion to devdeps

ralexandr commented 3 years ago

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

mikecousins commented 3 years ago

@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",
liamross commented 3 years ago

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?

LouGhys commented 3 years ago

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

This is what worked for us:

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

WIStudent commented 3 years ago

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:

viktorstrate commented 2 years ago

Any updates on this?

mccxiv commented 2 years ago

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

joaopedrodcf commented 2 years ago

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 apollo@2.20.0 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 commented 2 years ago

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 🙏

kierangillen commented 2 years ago

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",

c0bra commented 2 years ago

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

liamross commented 2 years ago

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

Differences:

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

cblaettl commented 2 years ago

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"
sergpetrov commented 2 years ago

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

tylermmorton commented 2 years ago

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.

mikecousins commented 2 years ago

How is this not getting more traction?

adamshaylor commented 2 years ago

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.

OuthBack commented 2 years ago

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

stephichau commented 2 years ago

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

OuthBack commented 2 years ago

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

ruben1gallardo2 commented 2 years ago

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

LinusU commented 2 years ago

It feels like some (peer-?)dependency is misconfigured in Apollo though, because I cannot run npx apollo@2.33.6 anymore, and that installs that version in it's own environment so it doesn't conflict with any other dependencies. That also means that I cannot select the version of graphql that gets installed though...

LukeAvsec-DarwinHomes commented 2 years ago

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",
edendattox commented 2 years ago

@LukeAvsec-DarwinHomes man you are a life saver

joietej commented 2 years ago

Adding GraphQL worked for me

fungiboletus commented 2 years ago

Another workaround if you only use the apollo service:* commands is switching to Apollo Rover because these commands are deprecated in Apollo CLI.

Minho-Lee commented 2 years ago

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!

traviscollins commented 2 years ago

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

masajid390 commented 2 years ago

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

nicodn commented 2 years ago

What worked for me on a mac:

brew install node@16
yarn global add apollo
carlosjunod commented 2 years ago

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

Ezra-Siton-UIX commented 2 years ago

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

matt2102 commented 2 years ago

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

janeklb commented 2 years ago

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

C-Yasitha commented 2 years ago

I think issue is on mac devices

I've tried on a windows PC instead of mac with following versions

apollo/2.34.0 win32-x64 node-v10.15.3

That worked for me

enBonnet commented 2 years ago

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

This is working well, thanks!

carlosalban commented 2 years ago

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

sescotti commented 2 years ago

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

fungiboletus commented 2 years ago

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.

sescotti commented 2 years ago

Consider using the Rover CLI instead of a deprecated tool.

Rover CLI doesn't support codegen yet