Skip to content

Remove stale user-level .npmrc instead of npmAuthenticate#7366

Merged
evgenyfedorov2 merged 1 commit intomainfrom
fix-npm-stale-user-npmrc
Mar 7, 2026
Merged

Remove stale user-level .npmrc instead of npmAuthenticate#7366
evgenyfedorov2 merged 1 commit intomainfrom
fix-npm-stale-user-npmrc

Conversation

@ilonatommy
Copy link
Member

@ilonatommy ilonatommy commented Mar 6, 2026

Problem

PR #7364 added npmAuthenticate@0 tasks to fix E401 errors, but PR #7361 is still failing (build 1323658). The npmAuthenticate tasks succeed but npm still sends stale credentials from the user-level C:\Users\cloudtest\.npmrc, overriding the project-level tokens.

Fix

Replace the two npmAuthenticate@0 tasks with a single step that removes the stale user-level .npmrc. Since the dotnet-public-npm feed is public, no authentication is needed — the problem was stale credentials being sent unnecessarily.

Why npmAuthenticate didn't work

npm merges config from multiple .npmrc files. The npmAuthenticate task writes fresh tokens to the project-level .npmrc, but npm also reads the user-level ~/.npmrc which has stale auth tokens for the same registry. The stale tokens get sent, causing E401.

Fixes #7365
Related: #7361, #7362, #7364

Microsoft Reviewers: Open in CodeFlow

@ilonatommy ilonatommy requested a review from a team as a code owner March 6, 2026 17:22
Copilot AI review requested due to automatic review settings March 6, 2026 17:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the CI pipeline template to address intermittent npm ci E401 failures on Windows agents caused by stale credentials in the user-level .npmrc, by removing that file before building the Azure DevOps plugin.

Changes:

  • Remove the previously-added npmAuthenticate@0 steps for the Azure DevOps plugin build.
  • Add a PowerShell step that deletes the user-level .npmrc on Windows to prevent npm from sending stale credentials to a public feed.

Replace the npmAuthenticate@0 tasks and .npmrc deletion with a scoped
NPM_CONFIG_USERCONFIG env var on just the Build Azure DevOps plugin step.
This points npm at a non-existent user config file so it ignores stale
credentials from C:\Users\cloudtest\.npmrc without affecting other jobs
on shared agents.

Verified locally: npm skips the user config section entirely when
NPM_CONFIG_USERCONFIG points to a non-existent path, while still
reading the project-level .npmrc for the registry URL.

Fixes #7365

Co-authored-by: Copilot <[email protected]>
@ilonatommy ilonatommy force-pushed the fix-npm-stale-user-npmrc branch from b708f38 to 19d9358 Compare March 6, 2026 18:04
@evgenyfedorov2 evgenyfedorov2 merged commit 125daf0 into main Mar 7, 2026
6 checks passed
@evgenyfedorov2 evgenyfedorov2 deleted the fix-npm-stale-user-npmrc branch March 7, 2026 09:42
ilonatommy added a commit that referenced this pull request Mar 9, 2026
Set NPM_CONFIG_USERCONFIG and NPM_CONFIG_GLOBALCONFIG at the top of
build.ps1 pointing to non-existent files. This makes all npm/npx calls
in the script ignore stale agent-level .npmrc credentials that cause
E401 errors against the public dotnet-public-npm feed.

This approach is more reliable than the AzDO env: block (PR #7366)
because:
- Pure PowerShell variable expansion (no AzDO macro issues)
- Covers BOTH user AND global config (previous only had user)
- Applies to all npm AND npx invocations in the script
- Scoped to this process only (no cross-job side effects)

Fixes #7365

Co-authored-by: Copilot <[email protected]>
ilonatommy added a commit that referenced this pull request Mar 9, 2026
Set NPM_CONFIG_USERCONFIG and NPM_CONFIG_GLOBALCONFIG at the top of
build.ps1 pointing to non-existent files. This makes all npm/npx calls
in the script ignore stale agent-level .npmrc credentials that cause
E401 errors against the public dotnet-public-npm feed.

This approach is more reliable than the AzDO env: block (PR #7366)
because:
- Pure PowerShell variable expansion (no AzDO macro issues)
- Covers BOTH user AND global config (previous only had user)
- Applies to all npm AND npx invocations in the script
- Scoped to this process only (no cross-job side effects)

Fixes #7365

Co-authored-by: Copilot <[email protected]>
ilonatommy added a commit that referenced this pull request Mar 12, 2026
The workarounds bypassed the custom .npmrc that sets the AzDO
dotnet-public-npm feed, which is required for SFI compliance.
The actual fix is to run scripts/UpdateNpmDependencies.ps1 to
ingest new upstream npm package versions into the feed.

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

npmAuthenticate@0 insufficient to fix E401: stale user-level .npmrc overrides project-level credentials

3 participants