Graphql-code-generator: Error while using with yarn@2

Created on 25 Jan 2020  ยท  12Comments  ยท  Source: dotansimha/graphql-code-generator

Describe the bug

I'm trying to use a package that uses @graphql-codegen/typescript as a dependency. When I try to run the program with the yarn@2 PnP system, the following error occurs:

A package is trying to access another package without the second one being listed as a dependency of the first one
  Required package: pascal-case (via "pascal-case")
  Required by: @graphql-codegen/visitor-plugin-common@virtual:aae36e88c4e0f74fc4a5c33f5d80547c8b1335956c1c197d1b6cff1fb078455a0e1661567ec9b5fd  ce7a6ba95d265ca12f85dc6caa30ad4bc6368dbdf13e1e4c#npm:1.11.2 

Environment:

  • OS: Linux Ubuntu 19.04
  • @graphql-codegen/...: ^1.4.0
  • NodeJS: 10.17.0
  • Yarn: 2.0.0
bug core waiting-for-release

All 12 comments

Could you try with the exact canary version? (Without ^ mark)
1.11.3-alpha-21386b4a.87+21386b4a

I got a similar error when upgrading a Gatsby project to yarn 2. Here is the full error message:

Error in "/Users/dany/code/nn/.yarn/cache/gatsby-plugin-generate-typings-npm-0.9.8-r1-a1515e494b-1.zip/node_modules/gatsby-plugin-generate-typings/gatsby-node.js": A package is trying to access another package without the second one being listed as a dependency of the first one

Required package: change-case (via "change-case")
Required by: @graphql-codegen/visitor-plugin-common@virtual:5aa3f7c89e79045d00730bd2aa57a38baebafdcdda91b45b7bcf1af205f5816c083ca900c8a05f8ad35f14a9568fa1a9ca3df60e17136d18ed93248418aae778#npm:1.4.0 (via /Users/dany/code/nn/.yarn/$$virtual/@graphql-codegen-visitor-plugin-common-virtual-9e4a35106c/0/cache/@graphql-codegen-visitor-plugin-common-npm-1.4.0-91b2768d55-1.zip/node_modules/@graphql-codegen/visitor-plugin-common/dist/commonjs/)

Require stack:
- /Users/dany/code/nn/.yarn/$$virtual/@graphql-codegen-visitor-plugin-common-virtual-9e4a35106c/0/cache/@graphql-codegen-visitor-plugin-common-npm-1.4.0-91b2768d55-1.zip/node_modules/@graphql-codegen/visitor-plugin-common/dist/commonjs/utils.js
- /Users/dany/code/nn/.yarn/$$virtual/@graphql-codegen-visitor-plugin-common-virtual-9e4a35106c/0/cache/@graphql-codegen-visitor-plugin-common-npm-1.4.0-91b2768d55-1.zip/node_modules/@graphql-codegen/visitor-plugin-common/dist/commonjs/index.js
- /Users/dany/code/nn/.yarn/$$virtual/@graphql-codegen-typescript-virtual-5aa3f7c89e/0/cache/@graphql-codegen-typescript-npm-1.4.0-48854446f4-1.zip/node_modules/@graphql-codegen/typescript/dist/commonjs/visitor.js
- /Users/dany/code/nn/.yarn/$$virtual/@graphql-codegen-typescript-virtual-5aa3f7c89e/0/cache/@graphql-codegen-typescript-npm-1.4.0-48854446f4-1.zip/node_modules/@graphql-codegen/typescript/dist/commonjs/index.js
- /Users/dany/code/nn/.yarn/cache/gatsby-plugin-generate-typings-npm-0.9.8-r1-a1515e494b-1.zip/node_modules/gatsby-plugin-generate-typings/gatsby-node.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bootstrap/resolve-module-exports.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bootstrap/load-plugins/validate.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bootstrap/load-plugins/load.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bootstrap/load-plugins/index.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bootstrap/index.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/commands/develop.js
- /Users/dany/code/nn/.yarn/cache/gatsby-cli-npm-2.7.44-fa8f05cd46-1.zip/node_modules/gatsby-cli/lib/create-cli.js
- /Users/dany/code/nn/.yarn/cache/gatsby-cli-npm-2.7.44-fa8f05cd46-1.zip/node_modules/gatsby-cli/lib/index.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bin/gatsby.js

In yarn.lock following version is specified:

"@graphql-codegen/visitor-plugin-common@npm:1.4.0":
  version: 1.4.0
  resolution: "@graphql-codegen/visitor-plugin-common@npm:1.4.0"
  dependencies:
    "@graphql-codegen/plugin-helpers": 1.4.0
    auto-bind: 2.0.0
    dependency-graph: 0.8.0
    graphql-tag: 2.10.1
    tslib: 1.10.0
  peerDependencies:
    graphql: ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0
  checksum: f550181c1b7280e1eda241ea001a1ed0c4e1ef10a8503a7513430d57ceca00546e86a4db13b7f65f80924e8857c7a8997dbf1ba16bef4b03829659837452a0bf
  languageName: node
  linkType: hard

Environment:

OS: Mac OS Catalina 10.15.2
NodeJS: v12.14.1
Yarn: 2.0.0-rc.27

Could you try the version I wrote above? @dcastil

Hey @ardatan! I missed your comment above mine, sorry for that!

I modified the yarn.lock file to use 1.11.3-alpha-21386b4a.87+21386b4a, resulting in following content:

"@graphql-codegen/visitor-plugin-common@npm:1.4.0":
  version: 1.11.3-alpha-21386b4a.87+21386b4a
  resolution: "@graphql-codegen/visitor-plugin-common@npm:1.11.3-alpha-21386b4a.87+21386b4a"
  dependencies:
    "@graphql-codegen/plugin-helpers": 1.4.0
    auto-bind: 2.0.0
    dependency-graph: 0.8.0
    graphql-tag: 2.10.1
    tslib: 1.10.0
  peerDependencies:
    graphql: ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0
  checksum: 3d69f846929451821fb293b15e9a62fef06eb2452d9ce1fa882f73b30f3452144da9dca62e392f5135a193200ca69e4fd9ac251d4761194cf218247a7a1d9026
  languageName: node
  linkType: hard

But I still get the same error unfortunately.

Error in "/Users/dany/code/nn/.yarn/cache/gatsby-plugin-generate-typings-npm-0.9.8-r1-a1515e494b-1.zip/node_modules/gatsby-plugin-generate-typings/gatsby-node.js": A package is trying to access another package without the second one being listed as a dependency of the first one

Required package: pascal-case (via "pascal-case")
Required by: @graphql-codegen/visitor-plugin-common@virtual:5aa3f7c89e79045d00730bd2aa57a38baebafdcdda91b45b7bcf1af205f5816c083ca900c8a05f8ad35f14a9568fa1a9ca3df60e17136d18ed93248418aae778#npm:1.11.3-alpha-21386b4a.87+21386b4a (via /Users/dany/code/nn/.yarn/$$virtual/@graphql-codegen-visitor-plugin-common-virtual-d5b58f324c/0/cache/@graphql-codegen-visitor-plugin-common-npm-1.11.3-alpha-21386b4a.87-206e333c63-1.zip/node_modules/@graphql-codegen/visitor-plugin-common/)

Require stack:
- /Users/dany/code/nn/.yarn/$$virtual/@graphql-codegen-visitor-plugin-common-virtual-d5b58f324c/0/cache/@graphql-codegen-visitor-plugin-common-npm-1.11.3-alpha-21386b4a.87-206e333c63-1.zip/node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js
- /Users/dany/code/nn/.yarn/$$virtual/@graphql-codegen-typescript-virtual-5aa3f7c89e/0/cache/@graphql-codegen-typescript-npm-1.4.0-48854446f4-1.zip/node_modules/@graphql-codegen/typescript/dist/commonjs/visitor.js
- /Users/dany/code/nn/.yarn/$$virtual/@graphql-codegen-typescript-virtual-5aa3f7c89e/0/cache/@graphql-codegen-typescript-npm-1.4.0-48854446f4-1.zip/node_modules/@graphql-codegen/typescript/dist/commonjs/index.js
- /Users/dany/code/nn/.yarn/cache/gatsby-plugin-generate-typings-npm-0.9.8-r1-a1515e494b-1.zip/node_modules/gatsby-plugin-generate-typings/gatsby-node.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bootstrap/resolve-module-exports.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bootstrap/load-plugins/validate.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bootstrap/load-plugins/load.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bootstrap/load-plugins/index.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bootstrap/index.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/commands/develop.js
- /Users/dany/code/nn/.yarn/cache/gatsby-cli-npm-2.7.44-fa8f05cd46-1.zip/node_modules/gatsby-cli/lib/create-cli.js
- /Users/dany/code/nn/.yarn/cache/gatsby-cli-npm-2.7.44-fa8f05cd46-1.zip/node_modules/gatsby-cli/lib/index.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bin/gatsby.js

Here is the proof that the alpha version was used indeed:

โฏ yarn why @graphql-codegen/visitor-plugin-common
โ”œโ”€ @graphql-codegen/typescript-operations@npm:1.4.0
โ”‚  โ””โ”€ @graphql-codegen/visitor-plugin-common@npm:1.11.3-alpha-21386b4a.87+21386b4a [642e2] (via npm:1.4.0 [642e2])
โ”‚
โ”œโ”€ @graphql-codegen/typescript@npm:1.4.0
โ”‚  โ””โ”€ @graphql-codegen/visitor-plugin-common@npm:1.11.3-alpha-21386b4a.87+21386b4a (via npm:1.4.0)
โ”‚
โ”œโ”€ @graphql-codegen/typescript@npm:1.4.0 [642e2]
โ”‚  โ””โ”€ @graphql-codegen/visitor-plugin-common@npm:1.11.3-alpha-21386b4a.87+21386b4a [642e2] (via npm:1.4.0 [642e2])
โ”‚
โ”œโ”€ @graphql-codegen/typescript@npm:1.4.0 [a1515]
โ”‚  โ””โ”€ @graphql-codegen/visitor-plugin-common@npm:1.11.3-alpha-21386b4a.87+21386b4a [5aa3f] (via npm:1.4.0 [5aa3f])
โ”‚
โ””โ”€ @nn/website@workspace:packages/nn-website
   โ””โ”€ @graphql-codegen/visitor-plugin-common@npm:1.11.3-alpha-21386b4a.87+21386b4a [61458] (via npm:1.11.3-alpha-21386b4a.87+21386b4a [61458])

Oh I just realized that gatsby plugin needs to be updated so it internally uses an old version of codegen. It'd be better to contact the maintainer of that package directly to use the latest version of codegen.

The problem is still present in the newest version. @graphql-codegen/visitor-plugin-common uses packages which are not specified in its package.json.

E.g. it uses pascal-case here

https://github.com/dotansimha/graphql-code-generator/blob/ebefbd443bdf45ef4e969e77f1f36631fc7ed801/packages/plugins/other/visitor-plugin-common/src/base-documents-visitor.ts#L10

but pascal-case isn't specified in @graphql-codegen/visitor-plugin-common's dependencies here

https://github.com/dotansimha/graphql-code-generator/blob/ebefbd443bdf45ef4e969e77f1f36631fc7ed801/packages/plugins/other/visitor-plugin-common/package.json#L10

@dcastil I think all dependencies are explicit and specified correctly in this PR
https://github.com/dotansimha/graphql-code-generator/pull/3388
You can test it 1.11.3-alpha-33d6634e.92

I tried running the Gatsby site with @graphql-codegen/[email protected] and got following output:

Error in "/Users/dany/code/nn/.yarn/cache/gatsby-plugin-generate-typings-npm-0.9.8-r1-a1515e494b-1.zip/node_modules/gatsby-plugin-generate-typings/gatsby-node.js": A package is trying to access another package without the second one being listed as a dependency of the first one

Required package: auto-bind (via "auto-bind")
Required by: @graphql-codegen/typescript@virtual:a1515e494bff02ddfdcd67977bcb8de489de51b1d943f520a28065244154d53d4171ce19e3e6cea6e885168406c2c63943dfa3b009d558797af5c4074f8349e8#npm:1.4.0 (via /Users/dany/code/nn/.yarn/$$virtual/@graphql-codegen-typescript-virtual-5aa3f7c89e/0/cache/@graphql-codegen-typescript-npm-1.4.0-48854446f4-1.zip/node_modules/@graphql-codegen/typescript/dist/commonjs/)

Require stack:
- /Users/dany/code/nn/.yarn/$$virtual/@graphql-codegen-typescript-virtual-5aa3f7c89e/0/cache/@graphql-codegen-typescript-npm-1.4.0-48854446f4-1.zip/node_modules/@graphql-codegen/typescript/dist/commonjs/visitor.js
- /Users/dany/code/nn/.yarn/$$virtual/@graphql-codegen-typescript-virtual-5aa3f7c89e/0/cache/@graphql-codegen-typescript-npm-1.4.0-48854446f4-1.zip/node_modules/@graphql-codegen/typescript/dist/commonjs/index.js
- /Users/dany/code/nn/.yarn/cache/gatsby-plugin-generate-typings-npm-0.9.8-r1-a1515e494b-1.zip/node_modules/gatsby-plugin-generate-typings/gatsby-node.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bootstrap/resolve-module-exports.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bootstrap/load-plugins/validate.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bootstrap/load-plugins/load.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bootstrap/load-plugins/index.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bootstrap/index.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/commands/develop.js
- /Users/dany/code/nn/.yarn/cache/gatsby-cli-npm-2.7.44-fa8f05cd46-1.zip/node_modules/gatsby-cli/lib/create-cli.js
- /Users/dany/code/nn/.yarn/cache/gatsby-cli-npm-2.7.44-fa8f05cd46-1.zip/node_modules/gatsby-cli/lib/index.js
- /Users/dany/code/nn/.yarn/unplugged/gatsby-virtual-45608c6932/node_modules/gatsby/dist/bin/gatsby.js

The error in @graphql-codegen/visitor-plugin-common doesn't appear anymore, instead one in @graphql-codegen/typescript is shown.

I can see that this was fixed in the PR diff, so this is probably due to the use of an old version of @graphql-codegen/typescript.

So I guess this issue is fixed, as long as v1.11.3 is released. Thank you! ๐Ÿ™

All implicit dependencies are specified in that PR so it will be fixed in the next release.

Hey @ardatan. Thank you so much for your response.
Do you have any estimated time, for when the next release will be available?

@Eddie-CooRo we'll release it today :)

Fixed in v1.12.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mszczepanczyk picture mszczepanczyk  ยท  3Comments

iamdanthedev picture iamdanthedev  ยท  3Comments

fvisticot picture fvisticot  ยท  3Comments

jagregory picture jagregory  ยท  3Comments

leebenson picture leebenson  ยท  3Comments