fix: add more info to the no matching version error message (#9225)

This commit is contained in:
Zoltan Kochan
2025-03-06 23:56:49 +01:00
committed by GitHub
parent 62407a99e3
commit 8371664f6f
3 changed files with 12 additions and 3 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/npm-resolver": patch
"pnpm": patch
---
When a package version cannot be found in the package metadata, print the registry from which the package was fetched.

View File

@@ -38,11 +38,11 @@ import { workspacePrefToNpm } from './workspacePrefToNpm'
export class NoMatchingVersionError extends PnpmError {
public readonly packageMeta: PackageMeta
constructor (opts: { wantedDependency: WantedDependency, packageMeta: PackageMeta }) {
constructor (opts: { wantedDependency: WantedDependency, packageMeta: PackageMeta, registry: string }) {
const dep = opts.wantedDependency.alias
? `${opts.wantedDependency.alias}@${opts.wantedDependency.pref ?? ''}`
: opts.wantedDependency.pref!
super('NO_MATCHING_VERSION', `No matching version found for ${dep}`)
super('NO_MATCHING_VERSION', `No matching version found for ${dep} while fetching it from ${opts.registry}`)
this.packageMeta = opts.packageMeta
}
}
@@ -198,7 +198,7 @@ async function resolveNpm (
// ignore
}
}
throw new NoMatchingVersionError({ wantedDependency, packageMeta: meta })
throw new NoMatchingVersionError({ wantedDependency, packageMeta: meta, registry: opts.registry })
}
const workspacePkgsMatchingName = workspacePackages?.get(pickedPackage.name)

View File

@@ -828,6 +828,7 @@ test('error is thrown when there is no package found for the requested version',
new NoMatchingVersionError({
wantedDependency,
packageMeta: isPositiveMeta,
registry,
})
)
})
@@ -870,6 +871,7 @@ test('error is thrown when there is no package found for the requested range', a
new NoMatchingVersionError({
wantedDependency,
packageMeta: isPositiveMeta,
registry,
})
)
})
@@ -888,6 +890,7 @@ test('error is thrown when there is no package found for the requested tag', asy
new NoMatchingVersionError({
wantedDependency,
packageMeta: isPositiveMeta,
registry,
})
)
})