parcel-bundler/parcel · error · ThrowableDiagnostic

Could not find module "${name}", but it was listed in packag

Error message

Could not find module "${name}", but it was listed in package.json. Run your package manager first.

What it means

Thrown by NodePackageManager.resolve() when a module name is found in package.json (dependencies/devDependencies/peerDependencies) but cannot be resolved on disk, AND getConflictingLocalDependencies returns non-null conflicts. The conflict means the module is declared in package.json but the installed version on disk conflicts with another local dependency requirement, preventing auto-install. The diagnostic includes JSON codeframes pointing to the package.json entry.

Source

Thrown at packages/core/package-manager/src/NodePackageManager.js:339

          this.fs,
          name,
          from,
          this.projectRoot,
        );

        if (conflicts == null) {
          this.invalidate(id, from);
          await this.install([{name, range: options?.range}], from, {
            saveDev: options?.saveDev ?? true,
          });

          return this.resolve(id, from, {
            ...options,
            shouldAutoInstall: false,
          });
        }

        throw new ThrowableDiagnostic({
          diagnostic: conflicts.fields.map(field => ({
            message: md`Could not find module "${name}", but it was listed in package.json. Run your package manager first.`,
            origin: '@parcel/package-manager',
            codeFrames: [
              {
                filePath: conflicts.filePath,
                language: 'json',
                code: conflicts.json,
                codeHighlights: generateJSONCodeHighlights(conflicts.json, [
                  {
                    key: `/${field}/${encodeJSONKeyComponent(name)}`,
                    type: 'key',
                    message: 'Defined here, but not installed',
                  },
                ]),
              },
            ],
          })),

View on GitHub (pinned to 59484858a1)

Solutions

  1. Run your package manager install: `npm install` or `yarn install` or `pnpm install`.
  2. Check for version conflicts in package.json — ensure all packages requesting the same dependency use compatible ranges.
  3. Delete node_modules and lockfiles, then reinstall from scratch if the conflict persists.
  4. If in a monorepo, run the install at the workspace root.

Example fix

// before: package.json declares dep but node_modules is stale
// "dependencies": { "lodash": "^4.17.20" }
// but lodash is missing or wrong version in node_modules

// after: run install
// $ npm install
Defensive patterns

Strategy: validation

Validate before calling

// Verify module is installed before resolving
const fs = require('fs');
const path = require('path');

function isModuleInstalled(name, from) {
  let dir = path.resolve(from);
  while (dir !== path.dirname(dir)) {
    let modulesPath = path.join(dir, 'node_modules', name);
    if (fs.existsSync(modulesPath)) return true;
    dir = path.dirname(dir);
  }
  return false;
}

if (!isModuleInstalled('my-module', __dirname)) {
  console.error('Run: npm install my-module');
}

Try / catch

try {
  let resolved = await packageManager.resolve(id, from, options);
} catch (e) {
  if (e.diagnostics?.[0]?.message?.includes('listed in package.json')) {
    // Module declared but not installed — run install
    console.error('Run npm/yarn/pnpm install first');
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: resolve() is called for a module that exists in package.json but not in node_modules. The code first tries to auto-install when conflicts==null, but when conflicts!=null it throws immediately because installing would violate a local dependency constraint. This typically happens when two packages require different versions of the same dependency.

Common situations: Running Parcel without first running `npm install` / `yarn install`. A monorepo where a shared dependency version conflicts between workspace packages. A package.json was edited to add a dependency but the install was never run. The node_modules directory is partially corrupted or was pruned.

Related errors


AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13). Data as JSON: /api/errors/b66c01eead0da747. Report an issue: GitHub.