Skip to content

Commit 198c5ea

Browse files
committed
feat: better error when package is not found
When a package is not found during installation, show which package is requiring it (if any) in the error message. If there is no parent request, throw the same error as before. Add new localized string 'requiredPackageNotFoundRegistry' which is the same 'packageNotFoundRegistry', but includes the parent package pattern.
1 parent 4924d70 commit 198c5ea

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/package-request.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,18 @@ export default class PackageRequest {
111111

112112
const Resolver = this.getRegistryResolver();
113113
const resolver = new Resolver(this, name, range);
114-
return resolver.resolve();
114+
try {
115+
return await resolver.resolve();
116+
} catch (err) {
117+
// if it is not an error thrown by yarn and it has a parent request,
118+
// thow a more readable error
119+
if (!(err instanceof MessageError) && this.parentRequest && this.parentRequest.pattern) {
120+
throw new MessageError(
121+
this.reporter.lang('requiredPackageNotFoundRegistry', pattern, this.parentRequest.pattern, this.registry),
122+
);
123+
}
124+
throw err;
125+
}
115126
}
116127

117128
/**

src/reporters/lang/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const messages = {
8080
invalidVersion: 'Invalid version supplied.',
8181
requiredVersionInRange: 'Required version in range.',
8282
packageNotFoundRegistry: "Couldn't find package $0 on the $1 registry.",
83+
requiredPackageNotFoundRegistry: "Couldn't find package $0 required by $1 on the $2 registry.",
8384
doesntExist: "Package $1 refers to a non-existing file '$0'.",
8485
missingRequiredPackageKey: `Package $0 doesn't have a $1.`,
8586
invalidAccess: 'Invalid argument for access, expected public or restricted.',

0 commit comments

Comments
 (0)