8

I'm trying to install express-graphql but getting this error. Please, help!

npm install --save express-graphql 
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: rest-api@1.0.0
npm ERR! Found: graphql@16.2.0
npm ERR! node_modules/graphql
npm ERR!   graphql@"^16.2.0" from the root project 
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer graphql@"^14.7.0 || ^15.3.0" from express-graphql@0.12.0
npm ERR! node_modules/express-graphql
npm ERR!   express-graphql@"*" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Udit Yadav
  • 99
  • 1
  • 7

14 Answers14

15

Delete the full initialized project then run the following:

npm init -y
npm install express express-graphql
npm install graphql

You should install express-graphql before graphql.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Rohan Tomar
  • 427
  • 4
  • 13
5

Uninstall graphql module if it's present. Then install both of them with one command:

npm install graphql express-graphql
3

I generated my app using:

npx express-generator <projectName>

and to solve the issue, I just did:

npm un express graphql

which where modules that I had already installed and then ran:

npm i express-graphql graphql express 

in that order worked for me.

MIG
  • 31
  • 1
2
  1. Delete package.json, package-lock.json, & node_modules.
  2. Initialize npm again.
  3. Now, install express-graphql with npm at first (install before any other package in the app).

These steps solve my problem.

Hemant Soni
  • 111
  • 7
1

Can you try deleting package-lock.json? It may help as per the github issue.

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
1

As stated in the other answers, first remove graphql via:

npm remove graphql

Now install express-graphql with this command:

npm install express-graphql

It works for me.

1

Install in this order:

npm install express-graphql graphql express
Rupesh
  • 11
  • 1
0

Install express-graphql before installing express.

0
npm install express-graphql --save --force

works for me.

Karikaalan
  • 44
  • 5
0

I deleted package-lock.json and ran

npm install express-graphql graphql --save

It worked for me.

Said
  • 1
0

I installed graphql then express-graphql, then npm i express --force

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
0

If you try to install express-graphql after graphql, it creates the conflict and that errors you see in the console. According to GraphQL spec, you should use the following modules installation order:

npm install express express-graphql graphql --save

To fix the issues, you should:

  1. Remove graphql
  2. Install express-graphql
  3. Install graphql
Lotpite
  • 336
  • 2
  • 4
0

STEP 1: Delete package.json, package-lock.json, node_modules and start again.

STEP 2: npm install express express-graphql graphql --save

Apparently installing packages in that order works. Command is copied from GraphQL docs. https://graphql.org/graphql-js/running-an-express-graphql-server/

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
0

install express-graphql with yarn

  1. install yarn npm install --global yarn
  2. install dependencieyarn add express-graphql
  3. be happy!