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

Typescript 5.5 is not working with yarn v4 and nodeLinker pnp, it forces switching to nodeLinker node-modules #58950

Closed
andrew-aladjev opened this issue Jun 20, 2024 · 4 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@andrew-aladjev
Copy link

andrew-aladjev commented Jun 20, 2024

πŸ”Ž Search Terms

Typescript 5.5 and yarn berry/canary/v3/v4/etc and pnp mode, found no bug reports.

πŸ•— Version & Regression Information

  • This changed between versions 5.4.5 and 5.5.0

⏯ Playground Link

No response

πŸ’» Code

Something has significantly changed from typescript 5.4.5 to 5.5.0. yarn config set nodeLinker pnp was working fine together with yarn exec tsc. Today I had to switch to yarn config set nodeLinker node-modules in order to use yarn exec tsc together with typescript 5.5.0.

Typescript config is standard:

{
  "include": ["src/**/*.ts"],
  "compilerOptions": {
    "target": "esnext",
    "lib": ["esnext"],
    "module": "NodeNext",
    "rootDir": "src",
    "moduleResolution": "nodenext",
    "outDir": "dist",
  }
}

πŸ™ Actual behavior

If you are trying to run yarn exec tsc (when yarn v4 is in pnp mode) than typescript 5.5.0 will fail with something like:

error TS2503: Cannot find namespace 'NodeJS'
error TS2304: Cannot find name 'setTimeout'
error TS2304: Cannot find name 'clearTimeout'

πŸ™‚ Expected behavior

yarn exec tsc (when yarn v4 is in pnp mode) works without errors.

Additional information about the issue

Did you break something related to node_modules dir in typescript 5.5.0? Thank you.

@andrew-aladjev
Copy link
Author

Sorry, it is hard to provide playground, because I see no sandboxes supports yarn in pnp mode. Please just use the following shell script:

mkdir ts-5.5.0 && cd ts-5.5.0
echo '{ "name": "bug-1", "private": true, "dependencies": { "typescript": "5.5.2", "@types/node": "*" } }' | jq > package.json
yarn set version stable
yarn config set nodeLinker pnp
yarn install
mkdir src && mkdir dist
echo 'setTimeout(() => {}, 0);' > src/bug.ts
echo '{ "include": ["src/**/*.ts"], "compilerOptions": { "target": "esnext", "lib": ["esnext"], "module": "NodeNext", "rootDir": "src", "moduleResolution": "nodenext", "outDir": "dist" }}' | jq > tsconfig.json
yarn exec tsc

Result is the following:

src/bug.ts:1:1 - error TS2304: Cannot find name 'setTimeout'.

You can fix it by using the following shell script:

yarn config set nodeLinker node-modules
yarn install
yarn exec tsc

And it will finish without errors.

@merceyz
Copy link

merceyz commented Jun 20, 2024

This happens with roughly every new TypeScript release but it's not on the TypeScript team to handle this.

You'll need to wait for yarnpkg/berry#6349 to be released or if you want you can use that PR version of Yarn by running the following in your project:

yarn set version from sources --branch 6349
yarn install

yarn exec tsc

You can "simplify" that to yarn tsc.

@jakebailey jakebailey added the External Relates to another program, environment, or user action which we cannot control. label Jun 20, 2024
@andrew-aladjev
Copy link
Author

@merceyz, Thank you, it works perfect. Lets wait until it will be released.

@merceyz
Copy link

merceyz commented Jun 21, 2024

It was released 22 minutes ago https://github.com/yarnpkg/berry/releases/tag/%40yarnpkg%2Fcli%2F4.3.1

hangxingliu added a commit to hangxingliu/yarn2-tsc-playground that referenced this issue Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

3 participants