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 <douglas@giantmonkey.de>
Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
douglasward
2023-05-17 01:08:37 +02:00
committed by GitHub
parent cdb2a93ed2
commit ea28b6f6c7
2 changed files with 7 additions and 0 deletions

View File

@@ -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).

View File

@@ -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"',
})