ADVERTISEMENT

GraphQL ERESOLVE unable to resolve dependency tree when building my docker container

The problem here is certainly with NPM and the packages you are trying to install rather than anything to do with Docker.

Unfortunately, I am not able to reproduce the exact error that you are facing. That could be because:

  • something changed in the time between now and whenever this problem occurred;
  • there are some essential details that you are not showing us.

Either way, there's a general way in which such issues are solved, which should help. But first an explanation.

Dependencies, peer dependencies and conflicts

NPM's package (dependency) management mechanism allows packages (dependencies) to have:

  • (direct) dependencies - installed automatically with the package;
  • peer dependencies - have to be manually installed by the consumer of the package.

However, NPM does not allow multiple versions of the same package to coexist.

Also, as you may know, packages use standard semantic versioning, which means that a major version change indicates a breaking change.

Due to these two reasons, clashes occur if one package requires dependency A to be v1, while another wants the same dependency A to be v2.

NPM v7

NPM v7 was recently released and this is the version that current (as of November 2020) node:current images use.

Probably the biggest changes brought about by NPM7 relate to peer dependencies - NPM should now be able to install them automatically, if possible. Read more here.

As described in the document, in cases where it's not possible to solve the conflicts, NPM should now throw errors rather than warnings, which is what you are seeing.

I, on the other hand, only managed to get warnings and no errors using your setup and NPM v7.0.8, and I don't know why. The problems reported were essentially the same, however, so the resolution ought to be very similar.

How to solve conflicts

The only solution that I'm aware of is manual conflict resolution - the developer needs to adjust their dependencies to play along.

In your specific case the problem seems to be with the graphql package. The latest graphql package is v15, which is also a peer dependency of the latest type-graphql package (v1).

However, apollo-server-express has a few dependencies, which apparently only support graphql up to and including v14.

While you wait for apollo-server-express to fully support v15, you may opt for graphql v14 altogether by downgrading the only package that requires v15. So if you change your npm install to this:

npm install --save cors apollo-server-express express [email protected] reflect-metadata [email protected] apollo-datasource-rest soap jsonwebtoken

it ought to work... Notice that we are explicitly installing [email protected] and [email protected] (yes, version zero).

Alternative solution

Going to give you some bad advice too. In some cases a missing peer dependency may not be a problem, particularly if you never use the related functionality. In your case, it may be even less of a problem because you do have the dependency, just not the required version. It's entirely possible that a wrong version would do just fine. If you feel lucky (or if you're sure of you're doing) and you really wish to proceed with graphql v15, you could either:

  • suppress any NPM output to silence the errors;
  • downgrade to NPM v6, which works quite differently (although it will still warn you of peer dependency problems).

Proceed with caution!


There is not need to downgrade to npm 6. Indeed npm 7 can still be used with option --legacy-peer-deps.

npm install --legacy-peer-deps