`ng update` fails with Yarn
Command
update
Is this a regression?
- [X] Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
<14 probably, not sure as it was a long time ago
Description
While updating a v15 application using Yarn (non-PnP), the ng update command fails with an unhelpful error.
The error claims there is no packageManager field in package.json, which is not true. Even if the field is really missing, ng update adds it but the next run will throw the same error.
The only workaround I found is to use npm to do the update (set packageManager: "[email protected]" in package.json, remove cli.packageManager from angular.json), and then revert to Yarn after the update.
It does not look like a Yarn issue, the behavior is the same with 3.4.1 or 4.2.2.
Minimal Reproduction
corepack enablenpx --package=@angular/cli@15 ng new ng15 --package-manager=yarn- add
.yarnrc.ymlwith content:nodeLinker: node-modules yarn installng update @angular/core@16 @angular/cli@16 --verbose --allow-dirty
Exception or Error
PS > ng update @angular/core@16 --verbose
Locating potential npmrc files:
Locating potential yarnrc files:
Trying 'C:\Users\me\.yarnrc'...found.
Trying 'C:\Users\me\.yarnrc'...found.
The installed Angular CLI version is outdated.
Installing a temporary Angular CLI versioned 16.2.14 to perform the update.
! The local project doesn't define a 'packageManager' field. Corepack will now add one referencing [email protected]+sha512.a333bf9c2557d71f5ba87dd1446cde24bb9c35301ec29dd2baba577b3f9d1ab61348b66a1324de9088c40a996c5b9203794da8bf14cab9fae6a6eccc00cb8078.
! For more details about this field, consult the documentation at https://nodejs.org/api/packages.html#packagemanager
✖ Packages installation failed, see above.
Your Environment
Angular CLI: 15.2.11
Node: 18.20.3
Package Manager: yarn 3.4.1
OS: win32 x64
Angular: 15.2.10
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1502.11
@angular-devkit/build-angular 15.2.11
@angular-devkit/core 15.2.11
@angular-devkit/schematics 15.2.11
@angular/cli 15.2.11
@schematics/angular 15.2.11
rxjs 7.8.1
typescript 4.9.5
Anything else relevant?
No response
I get a similar issue too - using WSL
I ran into this same issue when upgrading from v15 to v16 in a yarn monorepo and the steps mentioned here eventually got me past it.
TL;DR: temporarily switch to npm for the update command, then switch back to yarn.
Getting the same issue updating from v18 to v19.
The error says The local project doesn't define a 'packageManager' field. when it does. In package.json and also angular.json
I had a similar issue recently with a new v19 app, where things just wouldn't work with yarn. So I did the main scaffolding with npm, then migrated to yarn.