diff --git a/common/changes/@microsoft/rush/fix-rush-pnpm-npm-config-warnings_2026-03-23-18-16.json b/common/changes/@microsoft/rush/fix-rush-pnpm-npm-config-warnings_2026-03-23-18-16.json new file mode 100644 index 0000000000..219d8b2423 --- /dev/null +++ b/common/changes/@microsoft/rush/fix-rush-pnpm-npm-config-warnings_2026-03-23-18-16.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Fix \"Unknown env config\" warnings from npm during rush-pnpm operations (e.g. publish) by passing pnpm configuration via CLI args instead of NPM_CONFIG_* environment variables.", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} diff --git a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts index 1980c57f08..3a04deb7a7 100644 --- a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts +++ b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts @@ -432,12 +432,16 @@ export class RushPnpmCommandLineParser { const rushConfiguration: RushConfiguration = this._rushConfiguration; const workspaceFolder: string = this._subspace.getSubspaceTempFolderPath(); const pnpmEnvironmentMap: EnvironmentMap = new EnvironmentMap(process.env); - pnpmEnvironmentMap.set('NPM_CONFIG_WORKSPACE_DIR', workspaceFolder); + + // Pass pnpm configuration as CLI args rather than NPM_CONFIG_* environment variables. + // Using env vars like NPM_CONFIG_STORE_DIR would cause "Unknown env config" warnings + // when pnpm internally delegates to npm (e.g. during publish operations). + const pnpmConfigArgs: string[] = [`--config.workspaceDir=${workspaceFolder}`]; if (rushConfiguration.pnpmOptions.pnpmStorePath) { - pnpmEnvironmentMap.set('NPM_CONFIG_STORE_DIR', rushConfiguration.pnpmOptions.pnpmStorePath); - pnpmEnvironmentMap.set('NPM_CONFIG_CACHE_DIR', rushConfiguration.pnpmOptions.pnpmStorePath); - pnpmEnvironmentMap.set('NPM_CONFIG_STATE_DIR', rushConfiguration.pnpmOptions.pnpmStorePath); + pnpmConfigArgs.push(`--store-dir=${rushConfiguration.pnpmOptions.pnpmStorePath}`); + pnpmConfigArgs.push(`--config.cacheDir=${rushConfiguration.pnpmOptions.pnpmStorePath}`); + pnpmConfigArgs.push(`--config.stateDir=${rushConfiguration.pnpmOptions.pnpmStorePath}`); } if (rushConfiguration.pnpmOptions.environmentVariables) { @@ -473,7 +477,7 @@ export class RushPnpmCommandLineParser { try { const { exitCode } = await Utilities.executeCommandAsync({ command: rushConfiguration.packageManagerToolFilename, - args: this._pnpmArgs, + args: [...pnpmConfigArgs, ...this._pnpmArgs], workingDirectory: process.cwd(), environment: pnpmEnvironmentMap.toObject(), keepEnvironment: true,