yarnpkg/yarn · error · MessageError
moduleNotInManifest
Error message
moduleNotInManifest
What it means
For each requested package, yarn scans the registries/folders looking for it in a manifest; the `found` flag must become true (remove.js, loop ending around :73). If the package is not declared as a dependency anywhere, it throws moduleNotInManifest—you cannot remove what isn't installed.
Source
Thrown at src/cli/commands/remove.js:75
for (const type of constants.DEPENDENCY_TYPES) {
const deps = object[type];
if (deps && deps[name]) {
found = true;
delete deps[name];
}
}
const possibleManifestLoc = path.join(config.cwd, registry.folder, name);
if (await fs.exists(possibleManifestLoc)) {
const manifest = await config.maybeReadManifest(possibleManifestLoc, registryName);
if (manifest) {
manifests.push([possibleManifestLoc, manifest]);
}
}
}
if (!found) {
throw new MessageError(reporter.lang('moduleNotInManifest'));
}
}
// save manifests
await config.saveRootManifests(rootManifests);
// run hooks - npm runs these one after another
for (const action of ['preuninstall', 'uninstall', 'postuninstall']) {
for (const [loc] of manifests) {
await config.executeLifecycleScript(action, loc);
}
}
// reinstall so we can get the updated lockfile
reporter.step(++step, totalSteps, reporter.lang('uninstallRegenerate'), emoji.get('hammer'));
const installFlags = {force: true, workspaceRootIsCwd: true, ...flags};
const reinstall = new Install(installFlags, config, new NoopReporter(), lockfile);
await reinstall.init();View on GitHub (pinned to c2dda503f3)
Solutions
- Check the manifest: `node -p "Object.keys(require('./package.json').dependencies||{})"` and confirm the exact name spelling.
- If it's only transitive, you cannot remove it directly—instead update the package that brings it in, or run `yarn dedupe`/upgrade.
- If you're in a monorepo, ensure you're in the workspace whose package.json actually declares the dependency.
- Re-add the dependency first if you need to manage it through `yarn remove`.
Example fix
# before $ yarn remove lodahs # typo -> moduleNotInManifest # after $ yarn remove lodash
Defensive patterns
Strategy: validation
Validate before calling
const manifest = require('./package.json');
function isDeclaredDependency(name, pkg) {
const groups = ['dependencies','devDependencies','optionalDependencies','peerDependencies'];
return groups.some(g => pkg[g] && Object.prototype.hasOwnProperty.call(pkg[g], name));
}
if (!isDeclaredDependency(name, manifest)) {
throw new Error(`'${name}' is not declared in this package.json; cannot remove.`);
} Type guard
function isDeclaredDependency(name, pkg) {
const groups = ['dependencies','devDependencies','optionalDependencies','peerDependencies'];
return typeof pkg === 'object' && pkg !== null &&
groups.some(g => pkg[g] && Object.prototype.hasOwnProperty.call(pkg[g], name));
} Try / catch
try {
await runYarn(['remove', name]);
} catch (e) {
if (/moduleNotInManifest/.test(e.message)) {
console.error(`'${name}' is not a direct dependency here; check spelling/workspace.`);
return;
}
throw e;
} Prevention
- Remove only dependencies directly declared in the relevant package.json.
- Verify the exact name spelling before invoking remove.
- Ensure you're in the correct workspace whose manifest lists the dep.
When it happens
Trigger: Running `yarn remove <pkg>` where `<pkg>` is not listed in dependencies/devDependencies/optionalDependencies/peerDependencies of the current (or relevant) manifest.
Common situations: Typo in the package name; the package is only a transitive dependency (not directly listed); it was already removed; it lives in a different workspace than the CWD.
Related errors
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/f64801001ac654e2.
Report an issue: GitHub.