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

[Bug?]: yarn isn't loading @types packages after upgrading TS to 4.8.3 #4872

Closed
1 task
michaelfaith opened this issue Sep 20, 2022 · 10 comments
Closed
1 task
Labels
bug Something isn't working waiting for feedback Will autoclose in a while unless more data are provided

Comments

@michaelfaith
Copy link

Self-service

  • I'd be willing to implement a fix

Describe the bug

This afternoon I upgraded several projects in a monorepo using yarn 3 with pnp, and after upgrading TypeScript from 4.7.4 to 4.8.3, the rollup builds were no longer able to find types for node's path module, the process global object, or types for glob. It's a tiny project, so those are the only types I'm really using. I'm sure if it was a larger project it'd be worse.

To reproduce

This is company repo. If you're unable to reproduce, I can try and create a small public repro. Basically just TypeScript 4.8 using node and glob types, and the latest yarn with pnp

Environment

System:
    OS: Windows 10 10.0.19044
    CPU: (12) x64 11th Gen Intel(R) Core(TM) i5-11500H @ 2.90GHz
  Binaries:
    Node: 16.14.2 - ~\AppData\Local\Temp\xfs-9b01a4e7\node.CMD
    Yarn: 3.2.3 - ~\AppData\Local\Temp\xfs-9b01a4e7\yarn.CMD
    npm: 8.5.0 - C:\Program Files\nodejs\npm.CMD

Additional context

Error messages on build, after upgrade:

src/index.ts → build/cjs/index.js, build/esm/index.js...
[!] (plugin rpt2) Error: src/has-config-file.ts:7:25 - error TS2307: Cannot find module 'path' or its corresponding type declarations.

7 import { resolve } from 'path';
                          ~~~~~~
src/has-config-file.ts:9:18 - error TS2307: Cannot find module 'glob' or its corresponding type declarations.

9 import glob from 'glob';
                   ~~~~~~
src/has-config-file.ts:18:86 - error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

18   const { path: pkgPath } = readNearestPackage() || { packageJson: {}, path: resolve(process.cwd()) };
@michaelfaith michaelfaith added the bug Something isn't working label Sep 20, 2022
@merceyz
Copy link
Member

merceyz commented Sep 21, 2022

This is company repo. If you're unable to reproduce, I can try and create a small public repro.

We'll need a reproduction and please always provide one, it makes this easier and faster for everyone.

Basically just TypeScript 4.8 using node and glob types, and the latest yarn with pnp

I tried updating this repo to TypeScript v4.8.3 and yarn tsc works.

@merceyz merceyz added the waiting for feedback Will autoclose in a while unless more data are provided label Sep 21, 2022
@ezracelli
Copy link
Contributor

ezracelli commented Sep 27, 2022

EDIT: I just checked, and typescript@4.8.3 is actually working at the moment — should I open a new issue for 4.8.4?


Running into the same issue with typescript@4.8.4. Looks like the same issue as #3722

Note Cannot apply hunk #7 in the following (note that this error message only happens the first install, subsequent remove/adds fail silently):

$ yarn set version stable
➤ YN0000: Retrieving https://repo.yarnpkg.com/3.2.3/packages/yarnpkg-cli/bin/yarn.js
➤ YN0000: Saving the new release in .yarn/releases/yarn-3.2.3.cjs
➤ YN0000: Done in 0s 246ms

$ yarn init
{
  name: 'xxx',
  packageManager: 'yarn@3.2.3'
}

$ yarn add --dev typescript
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0013: │ typescript@npm:4.8.4 can't be found in the cache and will be fetched from the r
➤ YN0013: │ typescript@patch:typescript@npm%3A4.8.4#~builtin<compat/typescript>::version=4.
➤ YN0013: │ typescript@npm:4.8.4 can't be found in the cache and will be fetched from the r
➤ YN0066: │ typescript@patch:typescript@npm%3A4.8.4#~builtin<compat/typescript>::version=4.8.4&hash=a1c5e5: Cannot apply hunk #7
➤ YN0000: └ Completed in 8s 758ms
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: Done with warnings in 8s 943ms

Consequences:

$ yarn add --dev @types/node
-- snip --

$ yarn exec tsc --init
-- snip --

$ cat <<EOF > index.ts
import * as fs from "fs";

console.log(fs.readFileSync("./package.json", "utf-8"));
EOF

$ yarn exec tsc
index.ts:1:21 - error TS2307: Cannot find module 'fs' or its corresponding type declarations.

1 import * as fs from "fs";
                      ~~~~


Found 1 error in index.ts:1

Note: this also reproduces with yarn set version from sources.

@Ayc0
Copy link
Contributor

Ayc0 commented Sep 27, 2022

@merceyz or @arcanis is there an official process to release a new patch (like in #4738) for the newest versions of TS?

@merceyz
Copy link
Member

merceyz commented Sep 27, 2022

@ezracelli It will be fixed by #4903, if you need the fix right now you can run

yarn set version from sources --branch 4903

@merceyz or @arcanis is there an official process to release a new patch (like in #4738) for the newest versions of TS?

Not "official" but usually @arcanis or I update the patch then either of us backport and we release it soon after.
I've updated #4903 to include v4.8.4 as well.

@michaelfaith
Copy link
Author

michaelfaith commented Sep 28, 2022

EDIT: I just checked, and typescript@4.8.3 is actually working at the moment — should I open a new issue for 4.8.4?

Yeah, I think this issue is different. I've been trying to recreate this in a fresh project, moving one project at a time over from the main monorepo, and I've copied all of the important bits over now, and the new project is still working, and the old project is still failing. The only differences in beyond compare are some slightly newer patch versions on some of the transitive dependencies in the cache folder, and a slightly different yarn.lock and .pnp.cjs So I'm baffled why in two practically identical setups, one's working and the other isn't. Any advice on where to look? Are there properties of the .pnp.cjs file or within the .yarn folder that might be corrupted?

@damienbry
Copy link

damienbry commented Sep 28, 2022

@ezracelli I had a similar situation, downgrading to typescript@4.8.3 solved my case 🙌
FYI, I work on a monorepo with yarn workspaces using pnp and typescript

On one of my workspaces, I reverted to nodeLinker: node-modules in the .yarnrc.yml to make it work with typescript@4.8.4

@michaelfaith
Copy link
Author

So, I'm going to go ahead and close this as a non-issue. I re-cloned my repo to an entirely fresh checkout, and the branch that I was working in works in the new checkout (but still fails in the old checkout). So it must be something that's just corrupted in the local copy of my repo. It would be nice to understand how that happened, to avoid it in the future (as in, what kind of files might yarn or another library be holding on to that could cause this type of thing), but it doesn't make sense to spend more energy on it.

@dkress59
Copy link

For anyone else coming here, for me (Yarn3, pnp, workspaces) upgrading Yarn and its SDKs did the trick.

So after upgrading to typescript@4.8.4, run:
yarn set version stable && yarn dlx @yarnpkg/sdks vscode

@Poolshark
Copy link

Same seems to happen with Typescript v4.9.3. So far reverting to 4.8.4 worked. Is there a fix for 4.9.x already?

@arcanis
Copy link
Member

arcanis commented Nov 16, 2022

Yes, we just released 3.3.0 which should solve this problem.

@yarnpkg yarnpkg locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working waiting for feedback Will autoclose in a while unless more data are provided
Projects
None yet
Development

No branches or pull requests

8 participants