Skip to content

fix(@angular/cli): isolate temporary package installations from parent Yarn workspace - #33975

Open
clydin wants to merge 1 commit into
angular:mainfrom
clydin:fix-yarn-berry-temp-install
Open

fix(@angular/cli): isolate temporary package installations from parent Yarn workspace#33975
clydin wants to merge 1 commit into
angular:mainfrom
clydin:fix-yarn-berry-temp-install

Conversation

@clydin

@clydin clydin commented Aug 31, 2026

Copy link
Copy Markdown
Member

When installing a temporary CLI package during update command execution, the temporary directory is placed within the project tree (e.g. under node_modules). When using Yarn modern (v2+), Yarn searches upward for a yarn.lock file to locate the project root. Upon finding the parent project's yarn.lock, Yarn detects that the temporary directory contains a package.json but is not a declared workspace member, causing yarn add to fail with a Usage Error.

To resolve this, an empty yarn.lock file is written to the temporary directory when the package manager is Yarn modern. This creates a project boundary that prevents upward workspace traversal and ensures Yarn treats the directory as an independent project. Additionally, if the parent project does not define a .yarnrc.yml or .yarnrc.yaml, a default configuration specifying 'nodeLinker: node-modules' is written to ensure packages are installed into node_modules rather than PnP.

Fixes #33972

@clydin clydin added the target: patch This PR is targeted for the next patch release label Aug 31, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request ensures that when using Yarn, an empty yarn.lock is written to the temporary directory to prevent Yarn modern from traversing up the directory tree. It also writes a default .yarnrc.yml with nodeLinker: node-modules if no existing Yarn configuration is copied. Feedback on the changes highlights a potential issue where copiedYarnConfig is set to true before the configuration file is successfully written. If the write operation fails, the fallback configuration will not be written; moving the flag assignment after the write operation resolves this.

Comment thread packages/angular/cli/src/package-managers/package-manager.ts
…t Yarn workspace

When installing a temporary CLI package during update command execution,
the temporary directory is placed within the project tree (e.g. under
node_modules). When using Yarn modern (v2+), Yarn searches upward for
a yarn.lock file to locate the project root. Upon finding the parent
project's yarn.lock, Yarn detects that the temporary directory contains
a package.json but is not a declared workspace member, causing yarn add
to fail with a Usage Error.

To resolve this, an empty yarn.lock file is written to the temporary
directory when the package manager is Yarn modern. This creates a
project boundary that prevents upward workspace traversal and ensures
Yarn treats the directory as an independent project. Additionally, if
the parent project does not define a .yarnrc.yml or .yarnrc.yaml, a
default configuration specifying 'nodeLinker: node-modules' is written
to ensure packages are installed into node_modules rather than PnP.

Fixes angular#33972
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Aug 31, 2026
@clydin
clydin requested a review from alan-agius4 August 31, 2026 13:53
@clydin
clydin force-pushed the fix-yarn-berry-temp-install branch from 203eec1 to b4fd640 Compare August 31, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/cli target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ng update fails to install @angular/cli with yarn v4

1 participant