diff --git a/common/changes/@microsoft/rush/fix-pnpm-sync-modules-yaml_2025-06-23-08-37.json b/common/changes/@microsoft/rush/fix-pnpm-sync-modules-yaml_2025-06-23-08-37.json new file mode 100644 index 00000000000..9bf79c201b2 --- /dev/null +++ b/common/changes/@microsoft/rush/fix-pnpm-sync-modules-yaml_2025-06-23-08-37.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Fix pnpm-sync caused .modules.yaml ENOENT during install", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} \ No newline at end of file diff --git a/libraries/rush-lib/src/logic/base/BaseInstallManager.ts b/libraries/rush-lib/src/logic/base/BaseInstallManager.ts index 2bb9ec8afcf..f6c15e0e3e1 100644 --- a/libraries/rush-lib/src/logic/base/BaseInstallManager.ts +++ b/libraries/rush-lib/src/logic/base/BaseInstallManager.ts @@ -293,11 +293,12 @@ export abstract class BaseInstallManager { if (this.rushConfiguration.isPnpm && experiments?.usePnpmSyncForInjectedDependencies) { const pnpmLockfilePath: string = subspace.getTempShrinkwrapFilename(); const dotPnpmFolder: string = `${subspace.getSubspaceTempFolderPath()}/node_modules/.pnpm`; + const modulesFilePath: string = `${subspace.getSubspaceTempFolderPath()}/node_modules/.modules.yaml`; // we have an edge case here // if a package.json has no dependencies, pnpm will still generate the pnpm-lock.yaml but not .pnpm folder // so we need to make sure pnpm-lock.yaml and .pnpm exists before calling the pnpmSync APIs - if ((await FileSystem.existsAsync(pnpmLockfilePath)) && (await FileSystem.existsAsync(dotPnpmFolder))) { + if ((await FileSystem.existsAsync(pnpmLockfilePath)) && (await FileSystem.existsAsync(dotPnpmFolder)) && (await FileSystem.existsAsync(modulesFilePath))) { await pnpmSyncPrepareAsync({ lockfilePath: pnpmLockfilePath, dotPnpmFolder,