From f9f90158cc0acc4f4a03e0e02c13c2995d13c71d Mon Sep 17 00:00:00 2001 From: douglasward Date: Wed, 17 May 2023 01:08:37 +0200 Subject: [PATCH] fix: do not throw MISSING_HOISTED_LOCATIONS for optional packages (#6553) * do not throw MISSING_HOISTED_LOCATIONS for optional packages * docs: add changesets --------- Co-authored-by: Douglas Ward Co-authored-by: Zoltan Kochan --- .changeset/kind-windows-reflect.md | 6 ++++++ exec/plugin-commands-rebuild/src/implementation/index.ts | 1 + 2 files changed, 7 insertions(+) create mode 100644 .changeset/kind-windows-reflect.md diff --git a/.changeset/kind-windows-reflect.md b/.changeset/kind-windows-reflect.md new file mode 100644 index 00000000000..473639c316d --- /dev/null +++ b/.changeset/kind-windows-reflect.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-rebuild": patch +"pnpm": patch +--- + +`pnpm rebuild` should not fail when `node-linker` is set to `hoisted` and there are skipped optional dependencies [#6553](https://github.com/pnpm/pnpm/pull/6553). diff --git a/exec/plugin-commands-rebuild/src/implementation/index.ts b/exec/plugin-commands-rebuild/src/implementation/index.ts index 18e4a0962df..c0794effa5f 100644 --- a/exec/plugin-commands-rebuild/src/implementation/index.ts +++ b/exec/plugin-commands-rebuild/src/implementation/index.ts @@ -281,6 +281,7 @@ async function _rebuild ( ? (ctx.modulesFile?.hoistedLocations?.[depPath] ?? []).map((hoistedLocation) => path.join(opts.lockfileDir, hoistedLocation)) : [path.join(ctx.virtualStoreDir, dp.depPathToFilename(depPath), 'node_modules', pkgInfo.name)] if (pkgRoots.length === 0) { + if (pkgSnapshot.optional) return throw new PnpmError('MISSING_HOISTED_LOCATIONS', `${depPath} is not found in hoistedLocations inside node_modules/.modules.yaml`, { hint: 'If you installed your node_modules with pnpm older than v7.19.0, you may need to remove it and run "pnpm install"', })