yarnpkg/yarn · error · MessageError
ENOENT
ENOENT
Error message
Couldn't find a package.json file in $0
What it means
Thrown by `readManifest` (code 'ENOENT') when `maybeReadManifest` returns null for a directory — neither a yarn-metadata.json in cache nor a package.json under any registry filename was found. This is a hard failure variant of the soft null return; callers that require a manifest use `readManifest`, soft callers use `maybeReadManifest`.
Source
Thrown at src/config.js:690
remote: metadata.remote,
registry: metadata.registry,
};
});
}
/**
* Read normalized package info according yarn-metadata.json
* throw an error if package.json was not found
*/
readManifest(dir: string, priorityRegistry?: RegistryNames, isRoot?: boolean = false): Promise<Manifest> {
return this.getCache(`manifest-${dir}`, async (): Promise<Manifest> => {
const manifest = await this.maybeReadManifest(dir, priorityRegistry, isRoot);
if (manifest) {
return manifest;
} else {
throw new MessageError(this.reporter.lang('couldntFindPackagejson', dir), 'ENOENT');
}
});
}
/**
* try get the manifest file by looking
* 1. manifest file in cache
* 2. manifest file in registry
*/
async maybeReadManifest(dir: string, priorityRegistry?: RegistryNames, isRoot?: boolean = false): Promise<?Manifest> {
const metadataLoc = path.join(dir, constants.METADATA_FILENAME);
if (await fs.exists(metadataLoc)) {
const metadata = await this.readJson(metadataLoc);
if (!priorityRegistry) {
priorityRegistry = metadata.priorityRegistry;
}View on GitHub (pinned to c2dda503f3)
Solutions
- Run `yarn cache clean` and re-run `yarn install` to regenerate missing metadata.
- Remove the offending `node_modules` directory and reinstall: `rm -rf node_modules && yarn install`.
- If a workspace package is referenced, ensure its directory contains a valid package.json.
- Inspect the `dir` value in the error to find which package is missing its manifest.
Example fix
# before (broken cache/workspace) yarn install # after yarn cache clean rm -rf node_modules yarn install
Defensive patterns
Strategy: validation
Validate before calling
const fs = require('fs');
const path = require('path');
async function manifestExists(dir) {
const pkg = path.join(dir, 'package.json');
const meta = path.join(dir, '.yarn-metadata.json');
return fs.existsSync(pkg) || fs.existsSync(meta);
}
if (!(await manifestExists(targetDir))) {
console.error(`No package.json in ${targetDir} — run yarn install or restore the file.`);
process.exit(1);
} Try / catch
try {
return await config.readManifest(dir, priorityRegistry, isRoot);
} catch (err) {
if (err.code === 'ENOENT' && err instanceof MessageError) {
// gracefully skip or trigger reinstall
await fs.unlink(dir).catch(() => {});
throw new Error(`Missing manifest at ${dir} — run yarn cache clean && yarn install`);
}
throw err;
} Prevention
- Use `maybeReadManifest` (soft null) instead of `readManifest` when absence is tolerable.
- Validate that workspace glob targets each contain a package.json before install.
- Run `yarn cache clean` after corrupted or interrupted installs.
When it happens
Trigger: Calling `config.readManifest(dir)` where `dir` contains no package.json and no .yarn-metadata.json. Typically reached during install/link when a cache entry references a directory whose package.json was deleted, or when a workspace glob points at an empty/incomplete package.
Common situations: Corrupted or partially-deleted cache entry. A workspace folder exists but its package.json was removed. A dependency directory was truncated by an interrupted install. Manual deletion of node_modules contents.
Related errors
- Incorrect integrity when fetching from the cache for $0. Cac
- Incorrect hash when fetching from the cache for $0. Cache ha
- noName
- noVersion
- frozenLockfileError
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/f0443bc099305a9f.
Report an issue: GitHub.