diff --git a/cspell.json b/cspell.json index 4d37bfb416..f7e18dece3 100644 --- a/cspell.json +++ b/cspell.json @@ -216,6 +216,7 @@ "proxied", "pwsh", "quux", + "rcompare", "redownload", "refclone", "reflattened", diff --git a/resolving/npm-resolver/src/index.ts b/resolving/npm-resolver/src/index.ts index 191f762956..65b1e107d8 100644 --- a/resolving/npm-resolver/src/index.ts +++ b/resolving/npm-resolver/src/index.ts @@ -561,9 +561,16 @@ function tryResolveFromWorkspacePackages ( opts.update ? { name: spec.name, fetchSpec: '*', type: 'range' } : spec ) if (!localVersion) { + const availableVersions = Array.from(workspacePkgsMatchingName.keys()).sort((a, b) => semver.rcompare(a, b)) throw new PnpmError( 'NO_MATCHING_VERSION_INSIDE_WORKSPACE', - `In ${path.relative(process.cwd(), opts.projectDir)}: No matching version found for ${opts.wantedDependency.alias ?? ''}@${opts.wantedDependency.bareSpecifier ?? ''} inside the workspace` + `In ${path.relative(process.cwd(), opts.projectDir)}: No matching version found for ${opts.wantedDependency.alias ?? ''}@${opts.wantedDependency.bareSpecifier ?? ''} inside the workspace` + + (availableVersions.length ? `. Available versions: ${availableVersions.join(', ')}` : ''), + availableVersions.length + ? { + hint: `Available workspace versions for "${spec.name}": ${availableVersions.join(', ')}`, + } + : undefined ) } return resolveFromLocalPackage(workspacePkgsMatchingName.get(localVersion)!, spec, opts) diff --git a/resolving/npm-resolver/test/index.ts b/resolving/npm-resolver/test/index.ts index b0ae1d308b..b8d02b00ec 100644 --- a/resolving/npm-resolver/test/index.ts +++ b/resolving/npm-resolver/test/index.ts @@ -1702,7 +1702,7 @@ test('workspace protocol: resolution fails if there is no matching local package expect(err).toBeTruthy() expect(err.code).toBe('ERR_PNPM_NO_MATCHING_VERSION_INSIDE_WORKSPACE') - expect(err.message).toBe(`In ${path.relative(process.cwd(), projectDir)}: No matching version found for is-positive@workspace:^3.0.0 inside the workspace`) + expect(err.message).toBe(`In ${path.relative(process.cwd(), projectDir)}: No matching version found for is-positive@workspace:^3.0.0 inside the workspace. Available versions: 2.0.0`) }) test('workspace protocol: resolution fails if there are no local packages', async () => {