Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chenrui333 opened this issue Aug 12, 2021 · 68 comments
Open

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

chenrui333 opened this issue Aug 12, 2021 · 68 comments

Comments

@chenrui333
Copy link

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 Homebrew/homebrew-core#83152

@ralexandr
Copy link

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

@stephenh
Copy link

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?

@andrewlague
Copy link

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

@john-twigg-ck
Copy link

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

@matijs
Copy link

matijs commented Aug 13, 2021

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

@ralexandr @andrewlague @stephenh How did you downgrade?

@ralexandr
Copy link

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)

@Effanuel
Copy link

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

@andrewlague
Copy link

andrewlague commented Aug 13, 2021

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

@jedsada-gh
Copy link

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
Copy link

@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

@ralexandr
Copy link

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

@mikecousins
Copy link

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

@liamross
Copy link

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
Copy link

LouGhys commented Aug 27, 2021

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.

@WIStudent
Copy link

This issue is caused by apollo-language-server requiring @apollo/[email protected] but @apollo/[email protected] no longer working with graphql@14 (see apollographql/federation#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:

@viktorstrate
Copy link

Any updates on this?

@mccxiv
Copy link

mccxiv commented Sep 15, 2021

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

@joaopedrodcf
Copy link

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
Copy link

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 🙏

mfcochauxlaberge added a commit to arkipel/arkipel-client that referenced this issue Sep 19, 2021
@kierangillen
Copy link

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
Copy link

c0bra commented Sep 22, 2021

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

@liamross
Copy link

liamross commented Sep 28, 2021

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

@cblaettl
Copy link

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
Copy link

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

@tylermmorton
Copy link

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.

@janeklb
Copy link

janeklb commented Apr 19, 2022

@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
Copy link

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
Copy link

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
Copy link

carlosalban commented Jul 30, 2022

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

@sescotti
Copy link

sescotti commented Aug 4, 2022

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

@fungiboletus
Copy link

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
Copy link

sescotti commented Aug 5, 2022

Consider using the Rover CLI instead of a deprecated tool.

Rover CLI doesn't support codegen yet

@jose-ibh
Copy link

jose-ibh commented Aug 5, 2022

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

@sescotti I use M1 and this solution worked for me #2415 (comment)

@harakka
Copy link

harakka commented Aug 5, 2022

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.

@jalalmanafi
Copy link

Hi everyone , i had a same issue , just changed NODE version from 18 to 14 , it is worked for me , but i think this is not optimal way

@enBonnet
Copy link

enBonnet commented Aug 9, 2022

Hi everyone , i had a same issue , just changed NODE version from 18 to 14 , it is worked for me , but i think this is not optimal way

Did you try this? #2415 (comment)

@jalalmanafi
Copy link

Hi everyone , i had a same issue , just changed NODE version from 18 to 14 , it is worked for me , but i think this is not optimal way

Did you try this? #2415 (comment)

Honestly not , cause it i used this at tutorial , when i will need this at real project i will search for real solutions :)

@whitewaterdesign
Copy link

whitewaterdesign commented Aug 22, 2022

Thanks for the above...the following worked for me...

RUN npm install -g [email protected] [email protected]

running from Docker

FROM node:16.17.0
RUN npm install -g [email protected]

@chenrui333
Copy link
Author

This repo has been deprecated (see this comment)

@thril
Copy link

thril commented Feb 1, 2023

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

This was the solution that worked for me. Once I included the deprecated apollo package as a dependency, that caused the unzipped AWS lambda to be too large. Using the @apollo/rover dev dependency worked without problems.

// before ❌
npx apollo service:push <options>

// after ✅
rover subgraph publish <options>

kyh added a commit to kyh/2up that referenced this issue Sep 7, 2023
kyh added a commit to kyh/2up that referenced this issue Sep 8, 2023
kyh added a commit to kyh/2up that referenced this issue Sep 8, 2023
@Mpilo-Pillz
Copy link

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

@Nataraj-gn
Copy link

Below solution worked for me
https://www.appsloveworld.com/nodejs/100/127/error-cannot-find-module-graphql-validation-rules-possibletypeextensions
we just need to run sudo npm install -g graphql

@tezqa
Copy link

tezqa commented Sep 21, 2023

This worked for me:

"engines": {
  "node": ">=16"
},
"dependencies": {
  "graphql": "^16.8.1"
},
"devDependencies": {
  "apollo": "2.33.4",
  "apollo-language-server": "1.26.3"
}

@GIHAA
Copy link

GIHAA commented Dec 21, 2023

npm install -g graphql and npm install -g apollo worked for me

@LinusU
Copy link

LinusU commented Jan 8, 2024

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
  3. npx apollo@2 schema:download should now work 🎉

@julien-vu
Copy link

Apollo does not provide a schema download in the latest v3? I did not follow and I am still on the trick of using the v2

@smyrick
Copy link
Member

smyrick commented Apr 8, 2024

Apollo does not provide a schema download in the latest v3? I did not follow and I am still on the trick of using the v2

Correct, that functionality was moved to our more capable CLI, Rover, which has a command rover graph introspect

@avalevich
Copy link

Will this be fixed before GTA 6?

@Frontend-geonu
Copy link

any updates on this? 🙃

@smyrick
Copy link
Member

smyrick commented Oct 28, 2024

This thread has gotten quite long so let me summarize various comments already posted.

This repo and the CLI package apollo has been, for the most part, replaced with the more capable Rover CLI.

If you are trying to run these various commands, you can replace them with either other OSS tooling or a Rover command

  • client:codegen is now moved outside Apollo to the package@graphql-codegen/cli
  • client:download-schema is now rover graph introspect
  • client:extract is now for PQs with the package @apollo/persisted-query-lists (
  • client:push is now rover persisted-queries publish

The one remaining item we have it for client:check and the Rover team is actively looking at how we can get that added either their or to other equivalent tooling, but even for this one you could also use the package @graphql-cli/validate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests