fix: improve the error message when modules directory should be recreated (#7308)

This commit is contained in:
Zoltan Kochan
2023-11-14 11:43:15 +02:00
committed by GitHub
parent f2e9c3baaf
commit 2143a9388a
3 changed files with 9 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/get-context": patch
---
Improve the error message when `node_modules` should be recreated.

View File

@@ -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 () => {

View File

@@ -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, {