yarnpkg/yarn · error · MessageError
Package $0 doesn't have a $1.
Error message
Package $0 doesn't have a $1.
What it means
validateVersionInfo() iterates constants.REQUIRED_PACKAGE_KEYS (name and version) and throws if any key is falsy on the manifest. Yarn requires these keys for a structurally valid package definition before it can be added to the dependency graph.
Source
Thrown at src/package-request.js:358
// Now that we have all dependencies, it's safe to propagate optional
for (const otherRequest of ref.requests.slice(1)) {
ref.addOptional(otherRequest.optional);
}
}
/**
* TODO description
*/
static validateVersionInfo(info: Manifest, reporter: Reporter) {
// human readable name to use in errors
const human = `${info.name}@${info.version}`;
info.version = PackageRequest.getPackageVersion(info);
for (const key of constants.REQUIRED_PACKAGE_KEYS) {
if (!info[key]) {
throw new MessageError(reporter.lang('missingRequiredPackageKey', human, key));
}
}
}
/**
* Returns the package version if present, else defaults to the uid
*/
static getPackageVersion(info: Manifest): string {
// TODO possibly reconsider this behaviour
return info.version === undefined ? info._uid : info.version;
}
/**
* Gets all of the outdated packages and sorts them appropriately
*/
static async getOutdatedPackages(View on GitHub (pinned to c2dda503f3)
Solutions
- Inspect the source manifest of the failing package for missing name/version fields
- Pin to a known-good published version of the dependency
- Switch registry or mirror to one that serves complete packuments
- If using a file: or link: resolver, ensure the referenced package.json has name and version
Defensive patterns
Strategy: validation
Validate before calling
import * as constants from './constants.js';
function validateManifest(manifest) {
for (const key of constants.REQUIRED_PACKAGE_KEYS) {
if (!manifest[key]) {
return { valid: false, missing: key };
}
}
return { valid: true, missing: null };
} Type guard
function hasRequiredKeys(manifest: object, keys: string[]): boolean {
return keys.every(k => manifest[k] !== undefined && manifest[k] !== null && manifest[k] !== '');
} Try / catch
try {
PackageRequest.validateVersionInfo(info, reporter);
} catch (e) {
if (e.message.includes("doesn't have a")) {
// skip this manifest or fetch from an alternate source
}
} Prevention
- Validate fetched manifests against REQUIRED_PACKAGE_KEYS before resolution
- Avoid private registries that strip fields
- Test file:/git: dependencies have complete package.json files
When it happens
Trigger: A fetched manifest (from any resolver source) is missing its name or version field. Called from find() via validateVersionInfo() right after version extraction.
Common situations: Hand-crafted or malformed packages on private registries; exotic/file/git resolvers returning incomplete manifests; registry proxies stripping fields.
Related errors
- noName
- workspaceUnknownWorkspace
- The workspaces field in package.json must be an array.
- There are more than one workspace with name $0
- nohoist config is ignored in $0 because it is not a private
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/d4dc5e0ac2871533.
Report an issue: GitHub.