From 5c75ff3ec6a93dba871fe9fcb900fc4ff285f93d Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 23 Dec 2022 01:36:58 +0200 Subject: [PATCH] fix: rebuild should print a better error message (#5819) close #5815 --- .changeset/few-dancers-exist.md | 6 ++++++ .changeset/nervous-avocados-end.md | 6 ++++++ exec/plugin-commands-rebuild/package.json | 1 + exec/plugin-commands-rebuild/src/implementation/index.ts | 6 ++++++ exec/plugin-commands-rebuild/tsconfig.json | 3 +++ pnpm-lock.yaml | 3 +++ 6 files changed, 25 insertions(+) create mode 100644 .changeset/few-dancers-exist.md create mode 100644 .changeset/nervous-avocados-end.md diff --git a/.changeset/few-dancers-exist.md b/.changeset/few-dancers-exist.md new file mode 100644 index 00000000000..2d5ae8cce32 --- /dev/null +++ b/.changeset/few-dancers-exist.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-rebuild": patch +"pnpm": patch +--- + +`pnpm rebuild` should not fail if node_modules was created by pnpm version 7.18 or older [#5815](https://github.com/pnpm/pnpm/issues/5815). diff --git a/.changeset/nervous-avocados-end.md b/.changeset/nervous-avocados-end.md new file mode 100644 index 00000000000..d2dfd1dcc32 --- /dev/null +++ b/.changeset/nervous-avocados-end.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-rebuild": patch +"pnpm": patch +--- + +`pnpm rebuild` should print a better error message when a hoisted dependency is not found [#5815](https://github.com/pnpm/pnpm/issues/5815). diff --git a/exec/plugin-commands-rebuild/package.json b/exec/plugin-commands-rebuild/package.json index 887bf1d87d5..68c2dfac04b 100644 --- a/exec/plugin-commands-rebuild/package.json +++ b/exec/plugin-commands-rebuild/package.json @@ -34,6 +34,7 @@ "homepage": "https://github.com/pnpm/pnpm/blob/main/exec/plugin-commands-rebuild#readme", "devDependencies": { "@pnpm/assert-project": "workspace:*", + "@pnpm/error": "workspace:*", "@pnpm/filter-workspace-packages": "workspace:*", "@pnpm/plugin-commands-rebuild": "workspace:*", "@pnpm/prepare": "workspace:*", diff --git a/exec/plugin-commands-rebuild/src/implementation/index.ts b/exec/plugin-commands-rebuild/src/implementation/index.ts index 3522d6b7753..9c7f8e1bb4d 100644 --- a/exec/plugin-commands-rebuild/src/implementation/index.ts +++ b/exec/plugin-commands-rebuild/src/implementation/index.ts @@ -4,6 +4,7 @@ import { WANTED_LOCKFILE, } from '@pnpm/constants' import { skippedOptionalDependencyLogger } from '@pnpm/core-loggers' +import { PnpmError } from '@pnpm/error' import { getContext, PnpmContext } from '@pnpm/get-context' import { runLifecycleHooksConcurrently, @@ -276,6 +277,11 @@ async function _rebuild ( const pkgRoots = opts.nodeLinker === 'hoisted' ? (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) { + 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"', + }) + } const pkgRoot = pkgRoots[0] try { const extraBinPaths = ctx.extraBinPaths diff --git a/exec/plugin-commands-rebuild/tsconfig.json b/exec/plugin-commands-rebuild/tsconfig.json index 960b600c6de..fa291a77df2 100644 --- a/exec/plugin-commands-rebuild/tsconfig.json +++ b/exec/plugin-commands-rebuild/tsconfig.json @@ -48,6 +48,9 @@ { "path": "../../packages/dependency-path" }, + { + "path": "../../packages/error" + }, { "path": "../../packages/types" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 716d4b3e381..45ca4305438 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1046,6 +1046,9 @@ importers: '@pnpm/assert-project': specifier: workspace:* version: link:../../__utils__/assert-project + '@pnpm/error': + specifier: workspace:* + version: link:../../packages/error '@pnpm/filter-workspace-packages': specifier: workspace:* version: link:../../workspace/filter-workspace-packages