berry
berry copied to clipboard
[Bug?]: yarn isn't loading @types packages after upgrading TS to 4.8.3
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()) };
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.
EDIT: I just checked, and [email protected] is actually working at the moment — should I open a new issue for 4.8.4?
Running into the same issue with [email protected]. 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: '[email protected]'
}
$ 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.
@merceyz or @arcanis is there an official process to release a new patch (like in https://github.com/yarnpkg/berry/pull/4738) for the newest versions of TS?
@ezracelli It will be fixed by https://github.com/yarnpkg/berry/pull/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 https://github.com/yarnpkg/berry/pull/4903 to include v4.8.4 as well.
EDIT: I just checked, and
[email protected]is actually working at the moment — should I open a new issue for4.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?
@ezracelli I had a similar situation, downgrading to [email protected] 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 [email protected]
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.
For anyone else coming here, for me (Yarn3, pnp, workspaces) upgrading Yarn and its SDKs did the trick.
So after upgrading to [email protected], run:
yarn set version stable && yarn dlx @yarnpkg/sdks vscode
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?
Yes, we just released 3.3.0 which should solve this problem.