diff --git a/.changeset/gentle-flies-smash.md b/.changeset/gentle-flies-smash.md new file mode 100644 index 0000000000..ae6051efb5 --- /dev/null +++ b/.changeset/gentle-flies-smash.md @@ -0,0 +1,5 @@ +--- +"@pnpm/get-context": patch +--- + +Improve the error message when `node_modules` should be recreated. diff --git a/pkg-manager/core/test/lockfile.ts b/pkg-manager/core/test/lockfile.ts index 39eae52c8d..3ca48a7ef8 100644 --- a/pkg-manager/core/test/lockfile.ts +++ b/pkg-manager/core/test/lockfile.ts @@ -1094,7 +1094,7 @@ test('when using a different registry, add -g to the error report according to o err = _err } expect(err.code).toBe('ERR_PNPM_REGISTRIES_MISMATCH') - expect(err.message).toContain('pnpm install -g') + expect(err.hint).toContain('pnpm install -g') }) test('broken lockfile is fixed even if it seems like up to date at first. Unless frozenLockfile option is set to true', async () => { diff --git a/pkg-manager/get-context/src/index.ts b/pkg-manager/get-context/src/index.ts index 1220c72c5c..6ed47ce320 100644 --- a/pkg-manager/get-context/src/index.ts +++ b/pkg-manager/get-context/src/index.ts @@ -291,7 +291,9 @@ async function validateModules ( await purgeModulesDirsOfImporters(opts, projects) return { purged: true } } - throw new PnpmError('REGISTRIES_MISMATCH', `This modules directory was created using the following registries configuration: ${JSON.stringify(modules.registries)}. The current configuration is ${JSON.stringify(opts.registries)}. To recreate the modules directory using the new settings, run "pnpm install${opts.global ? ' -g' : ''}".`) + throw new PnpmError('REGISTRIES_MISMATCH', `This modules directory was created using the following registries configuration: ${JSON.stringify(modules.registries)}. The current configuration is ${JSON.stringify(opts.registries)}.`, { + hint: `To recreate the modules directory using the new settings, run "pnpm install${opts.global ? ' -g' : ''}".`, + }) } if (purged && (rootProject == null)) { await purgeModulesDirsOfImporter(opts, {