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

Quickstart needs ts-node #8685

Closed
brandon-leapyear opened this issue Dec 2, 2022 · 6 comments
Closed

Quickstart needs ts-node #8685

brandon-leapyear opened this issue Dec 2, 2022 · 6 comments
Labels
core Related to codegen core/cli stage/6-released The issue has been solved on a released version of the library

Comments

@brandon-leapyear
Copy link
Contributor

brandon-leapyear commented Dec 2, 2022

Which packages are impacted by your issue?

No response

Describe the bug

The quickstart in the README + website are both missing yarn add -D ts-node, which is needed as a peer dependency of @graphql-codegen/cli.

Your Example Website or App

N/A

Steps to Reproduce the Bug or Issue

  1. yarn set version stable
  2. yarn add graphql && yarn add -D typescript && yarn add -D @graphql-codegen/cli
  3. yarn graphql-codegen init
Error: cosmiconfig-typescript-loader tried to access ts-node (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.

Required package: ts-node
Required by: cosmiconfig-typescript-loader@virtual:c2008e4899b4ad3fb5e4082351d2290b40b46638c098d3b98067292e092b49aedc20e75b2d0d7299469f1f327eadef39c959b82821fc471e0d7c154a6d82f2ad#npm:4.1.1 (via /Users/bchinn/Desktop/foo/.yarn/__virtual__/cosmiconfig-typescript-loader-virtual-33f90becc5/0/cache/cosmiconfig-typescript-loader-npm-4.1.1-77b25222d1-a774961868.zip/node_modules/cosmiconfig-typescript-loader/dist/cjs/)

Ancestor breaking the chain: @graphql-codegen/cli@virtual:dc3fc578bfa5e06182a4d2be39ede0bc5b74940b1ffe0d70c26892ab140a4699787750fba175dc306292e80b4aa2c8c5f68c2a821e69b2c37e360c0dff36ff66#npm:2.15.0

Expected behavior

Should work

Screenshots or Videos

No response

Platform

  • OS: macOS
  • NodeJS: [e.g. 18.5.0]
  • graphql version: [e.g. 16.3.0]
  • @graphql-codegen/* version(s): [e.g. 2.6.2]

Codegen Config File

No response

Additional context

No response

@saihaj
Copy link
Collaborator

saihaj commented Dec 2, 2022

There is nothing in CLI that uses ts-node. I build and run it with just node and works fine. Only peerDep we have is graphql

"dependencies": {
"@babel/generator": "^7.18.13",
"@babel/template": "^7.18.10",
"@babel/types": "^7.18.13",
"@graphql-codegen/core": "2.6.6",
"@graphql-codegen/plugin-helpers": "^2.7.2",
"@graphql-tools/apollo-engine-loader": "^7.3.6",
"@graphql-tools/code-file-loader": "^7.3.13",
"@graphql-tools/git-loader": "^7.2.13",
"@graphql-tools/github-loader": "^7.3.20",
"@graphql-tools/graphql-file-loader": "^7.5.0",
"@graphql-tools/json-file-loader": "^7.4.1",
"@graphql-tools/load": "7.8.0",
"@graphql-tools/prisma-loader": "^7.2.7",
"@graphql-tools/url-loader": "^7.13.2",
"@graphql-tools/utils": "^8.9.0",
"@whatwg-node/fetch": "^0.3.0",
"chalk": "^4.1.0",
"chokidar": "^3.5.2",
"cosmiconfig": "^7.0.0",
"cosmiconfig-typescript-loader": "4.1.1",
"debounce": "^1.2.0",
"detect-indent": "^6.0.0",
"graphql-config": "4.3.6",
"inquirer": "^8.0.0",
"is-glob": "^4.0.1",
"json-to-pretty-yaml": "^1.2.2",
"listr2": "^4.0.5",
"log-symbols": "^4.0.0",
"shell-quote": "^1.7.3",
"string-env-interpolation": "^1.0.1",
"ts-log": "^2.2.3",
"tslib": "^2.4.0",
"yaml": "^1.10.0",
"yargs": "^17.0.0"
},
"devDependencies": {
"@graphql-tools/merge": "8.3.4",
"@types/debounce": "1.2.1",
"@types/inquirer": "8.2.3",
"@types/is-glob": "4.0.2",
"@types/js-yaml": "4.0.5",
"@types/mkdirp": "1.0.2",
"@types/shell-quote": "1.7.1",
"bdd-stdin": "0.2.0",
"change-case-all": "1.0.14",
"js-yaml": "4.1.0",
"make-dir": "3.1.0",
"prettier": "2.7.1"
},
"peerDependencies": {
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
},

@saihaj saihaj added the stage/0-issue-prerequisites Needs more information before we can start working on it label Dec 2, 2022
@brandon-leapyear
Copy link
Contributor Author

brandon-leapyear commented Dec 2, 2022

This is an old work account. Please reference @brandonchinn178 for all future communication


The CLI uses cosmiconfig-typescript-loader which uses ts-node:

// #8437: conflict with `graphql-config` also using TypeScriptLoader(), causing a double `ts-node` register.
const tsLoader = TypeScriptLoader({ transpileOnly: true });
return tsLoader(filepath, content);

It fails on Yarn because Yarn uses PnP and errors if packages try to access a package they don't mention in their dependencies:
https://yarnpkg.com/getting-started/migration#fix-dependencies-with-packageextensions

Did you try running through the repro steps I had in the issue?

EDIT: current workaround is to update .yarnrc.yml:

packageExtensions:
  '@graphql-codegen/cli@*':
    'ts-node': '*'

but @graphql-codegen/cli should be updated to include ts-node as a peer dependency

@sjdemartini
Copy link

I'm also experiencing this, and it appears to be a duplicate of this slightly older open issue #8462.

Per https://yarnpkg.com/advanced/error-codes#yn0002---missing_peer_dependency, this is a problem that should be fixed by @graphq-codegen/cli to resolve the various missing peer deps requested by its dependencies, so that the manual packageExtensions workaround in yarn isn't needed to patch it.

Here's the yarn install output with yarn 2+:

➤ YN0002: │ @graphql-codegen/cli@npm:2.16.1 [d9650] doesn't provide @types/node (p8dcee), requested by cosmiconfig-typescript-loader
➤ YN0002: │ @graphql-codegen/cli@npm:2.16.1 [d9650] doesn't provide ts-node (p32fa9), requested by cosmiconfig-typescript-loader
➤ YN0002: │ @graphql-codegen/cli@npm:2.16.1 [d9650] doesn't provide typescript (p51647), requested by cosmiconfig-typescript-loader

@saihaj saihaj added the core Related to codegen core/cli label Dec 15, 2022
@louisscruz
Copy link
Contributor

I'm also hitting this issue in a fresh project on Yarn 3.

The workaround listed above should be:

packageExtensions:
  "@graphql-codegen/cli@*":
    peerDependencies:
      "ts-node": "*"

The above should be added to your .yarnrc.yml and run yarn for the extension to kick in.

@louisscruz
Copy link
Contributor

PR for a fix over here: #8779

@saihaj
Copy link
Collaborator

saihaj commented Jan 4, 2023

@saihaj saihaj closed this as completed Jan 4, 2023
@saihaj saihaj added stage/6-released The issue has been solved on a released version of the library and removed stage/0-issue-prerequisites Needs more information before we can start working on it labels Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to codegen core/cli stage/6-released The issue has been solved on a released version of the library
Projects
None yet
Development

No branches or pull requests

4 participants