{"record":{"id":"f64801001ac654e2","repo":"yarnpkg/yarn","slug":"modulenotinmanifest","errorCode":null,"errorMessage":"moduleNotInManifest","messagePattern":"moduleNotInManifest","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/cli/commands/remove.js","lineNumber":75,"sourceCode":"      for (const type of constants.DEPENDENCY_TYPES) {\n        const deps = object[type];\n        if (deps && deps[name]) {\n          found = true;\n          delete deps[name];\n        }\n      }\n\n      const possibleManifestLoc = path.join(config.cwd, registry.folder, name);\n      if (await fs.exists(possibleManifestLoc)) {\n        const manifest = await config.maybeReadManifest(possibleManifestLoc, registryName);\n        if (manifest) {\n          manifests.push([possibleManifestLoc, manifest]);\n        }\n      }\n    }\n\n    if (!found) {\n      throw new MessageError(reporter.lang('moduleNotInManifest'));\n    }\n  }\n\n  // save manifests\n  await config.saveRootManifests(rootManifests);\n\n  // run hooks - npm runs these one after another\n  for (const action of ['preuninstall', 'uninstall', 'postuninstall']) {\n    for (const [loc] of manifests) {\n      await config.executeLifecycleScript(action, loc);\n    }\n  }\n\n  // reinstall so we can get the updated lockfile\n  reporter.step(++step, totalSteps, reporter.lang('uninstallRegenerate'), emoji.get('hammer'));\n  const installFlags = {force: true, workspaceRootIsCwd: true, ...flags};\n  const reinstall = new Install(installFlags, config, new NoopReporter(), lockfile);\n  await reinstall.init();","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/remove.js#L57-L93","documentation":"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.","triggerScenarios":"Running `yarn remove <pkg>` where `<pkg>` is not listed in dependencies/devDependencies/optionalDependencies/peerDependencies of the current (or relevant) manifest.","commonSituations":"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.","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`."],"exampleFix":"# before\n$ yarn remove lodahs   # typo -> moduleNotInManifest\n# after\n$ yarn remove lodash","handlingStrategy":"validation","validationCode":"const manifest = require('./package.json');\nfunction isDeclaredDependency(name, pkg) {\n  const groups = ['dependencies','devDependencies','optionalDependencies','peerDependencies'];\n  return groups.some(g => pkg[g] && Object.prototype.hasOwnProperty.call(pkg[g], name));\n}\nif (!isDeclaredDependency(name, manifest)) {\n  throw new Error(`'${name}' is not declared in this package.json; cannot remove.`);\n}","typeGuard":"function isDeclaredDependency(name, pkg) {\n  const groups = ['dependencies','devDependencies','optionalDependencies','peerDependencies'];\n  return typeof pkg === 'object' && pkg !== null &&\n    groups.some(g => pkg[g] && Object.prototype.hasOwnProperty.call(pkg[g], name));\n}","tryCatchPattern":"try {\n  await runYarn(['remove', name]);\n} catch (e) {\n  if (/moduleNotInManifest/.test(e.message)) {\n    console.error(`'${name}' is not a direct dependency here; check spelling/workspace.`);\n    return;\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["cli","remove","manifest","dependencies"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}