yarnpkg/yarn · error · MessageError

foundErrors

Error message

foundErrors

What it means

`yarn check --verify-tree` walks `node_modules` and reports one error per defect via `reportError` (which increments `errCount`). At `check.js:152`, if `errCount > 0`, it throws `foundErrors` with the count. The errors aggregated here are `packageNotInstalled` and `packageWrongVersion` — installed tree does not match the lockfile/manifest.

Source

Thrown at src/cli/commands/check.js:152

              version: dependencies[subdep],
            });
            found = true;
            break;
          }
          if (!locations.length) {
            break;
          }
          locations.pop();
        }
        if (!found) {
          reportError('packageNotInstalled', `${dep.originalKey}#${subdep}`);
        }
      }
    }
  }

  if (errCount > 0) {
    throw new MessageError(reporter.lang('foundErrors', errCount));
  } else {
    reporter.success(reporter.lang('folderInSync'));
  }
}

async function integrityHashCheck(
  config: Config,
  reporter: Reporter,
  flags: Object,
  args: Array<string>,
): Promise<void> {
  let errCount = 0;
  function reportError(msg, ...vars) {
    reporter.error(reporter.lang(msg, ...vars));
    errCount++;
  }
  const integrityChecker = new InstallationIntegrityChecker(config);

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Run `yarn install --force` to reconcile the tree.
  2. If still failing: `rm -rf node_modules && yarn install`.
  3. Inspect the individual `packageNotInstalled`/`packageWrongVersion` lines above the throw for the specific offender.

Example fix

// before
$ yarn check --verify-tree
→ Found 3 errors.

// after
$ rm -rf node_modules yarn.lock
$ yarn install
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check that every declared dependency is physically present
import fs from 'fs';
import path from 'path';

async function depsPresent(rootDeps: Record<string,string>, cwd: string): Promise<string[]> {
  const missing: string[] = [];
  for (const name of Object.keys(rootDeps)) {
    if (!fs.existsSync(path.join(cwd, 'node_modules', name, 'package.json'))) missing.push(name);
  }
  return missing;
}
// if ((await depsPresent(pkg.dependencies, cwd)).length) await rebuild();

Try / catch

try {
  await check(config, reporter, { verifyTree: true }, []);
} catch (e) {
  if (/Found \d+ errors/.test(e.message)) {
    await rebuildNodeModules(); // rm -rf node_modules && yarn install
  } else throw e;
}

Prevention

When it happens

Trigger: Any `reportError('packageNotInstalled'|'packageWrongVersion', ...)` call during the verify-tree loop, i.e. a package listed in dependencies is missing from node_modules or its installed version does not satisfy the declared range.

Common situations: Partially populated `node_modules` after an interrupted install, manual deletion of a package, drift between `package.json`/`yarn.lock` and the on-disk tree, or platform-specific optional deps not cleaned up.

Related errors


AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13). Data as JSON: /api/errors/c828155e66f0d7ab. Report an issue: GitHub.