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

Error: @nestjs/mercurius tried to access graphql and mercurius and lodash, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound. #2129

Closed
2 of 4 tasks
ceefour opened this issue Apr 9, 2022 · 2 comments

Comments

@ceefour
Copy link

ceefour commented Apr 9, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

@nestjs/mercurius uses graphql without listing it in its dependencies. It works in certain hoisting layouts because it hijacks it from other package

This creates issues when using the package with Yarn's PnP resolution, and I assume also breaks the pnpm package manager.

See:

Minimum reproduction code

Steps to reproduce

With an empty app as in https://docs.nestjs.com/graphql/quick-start#mercurius-integration

yarn set version berry

Then edit .yarnrc.yml and set node-linker to pnp

yarn start:dev will no longer start.

This is very similar to #1162

Expected behavior

All imported packages should be listed in package.json. (maybe as peer dependencies?) Specifically:

  1. graphql
  2. mercurius
  3. lodash

Package version

10.0.8

Graphql version

graphql: 16.3.0
apollo-server-express: not used
apollo-server-fastify: not used
@nestjs/platform-fastify: 8.4.4
@nestjs/mercurius: 10.0.8

NestJS version

8.4.4

Node.js version

16.14.2

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@ceefour ceefour changed the title Error: @nestjs/mercurius tried to access graphql, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound. Error: @nestjs/mercurius tried to access graphql and mercurius, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound. Apr 9, 2022
@ceefour ceefour changed the title Error: @nestjs/mercurius tried to access graphql and mercurius, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound. Error: @nestjs/mercurius tried to access graphql and mercurius and lodash, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound. Apr 9, 2022
@kamilmysliwiec
Copy link
Member

Would you like to create a PR adding graphql as a peer dependency? Note: this might be problematic as mercurius incorrectly marks graphql as a dependency (while it should be a peer dependency instead) mercurius-js/mercurius#711

@hwasurr
Copy link
Contributor

hwasurr commented Jul 13, 2022

This issue also occurs when Express and Apollo are installed using yarn 'PnP'. In this case, graphql and apollo-server-core can't be resolved.
I temporarily solved this by adding a few lines of code to the .yarnrc.yml and add apollo-server-core as a dependency in my nestjs project.

packageExtensions:
  "@nestjs/apollo@*":
    peerDependencies:
      "graphql": "*"

Anyway, I'm not sure if there will be any other side effects, but I can make a PR adding graphql as a peer dependency.

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

No branches or pull requests

3 participants