{"record":{"id":"b66c01eead0da747","repo":"parcel-bundler/parcel","slug":"could-not-find-module-name-but-it-was-listed","errorCode":null,"errorMessage":"Could not find module \"${name}\", but it was listed in package.json. Run your package manager first.","messagePattern":"Could not find module \"(.+?)\", but it was listed in package\\.json\\. Run your package manager first\\.","errorType":"exception","errorClass":"ThrowableDiagnostic","httpStatus":null,"severity":"error","filePath":"packages/core/package-manager/src/NodePackageManager.js","lineNumber":339,"sourceCode":"          this.fs,\n          name,\n          from,\n          this.projectRoot,\n        );\n\n        if (conflicts == null) {\n          this.invalidate(id, from);\n          await this.install([{name, range: options?.range}], from, {\n            saveDev: options?.saveDev ?? true,\n          });\n\n          return this.resolve(id, from, {\n            ...options,\n            shouldAutoInstall: false,\n          });\n        }\n\n        throw new ThrowableDiagnostic({\n          diagnostic: conflicts.fields.map(field => ({\n            message: md`Could not find module \"${name}\", but it was listed in package.json. Run your package manager first.`,\n            origin: '@parcel/package-manager',\n            codeFrames: [\n              {\n                filePath: conflicts.filePath,\n                language: 'json',\n                code: conflicts.json,\n                codeHighlights: generateJSONCodeHighlights(conflicts.json, [\n                  {\n                    key: `/${field}/${encodeJSONKeyComponent(name)}`,\n                    type: 'key',\n                    message: 'Defined here, but not installed',\n                  },\n                ]),\n              },\n            ],\n          })),","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/package-manager/src/NodePackageManager.js#L321-L357","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run your package manager install: `npm install` or `yarn install` or `pnpm install`.","Check for version conflicts in package.json — ensure all packages requesting the same dependency use compatible ranges.","Delete node_modules and lockfiles, then reinstall from scratch if the conflict persists.","If in a monorepo, run the install at the workspace root."],"exampleFix":"// before: package.json declares dep but node_modules is stale\n// \"dependencies\": { \"lodash\": \"^4.17.20\" }\n// but lodash is missing or wrong version in node_modules\n\n// after: run install\n// $ npm install","handlingStrategy":"validation","validationCode":"// Verify module is installed before resolving\nconst fs = require('fs');\nconst path = require('path');\n\nfunction isModuleInstalled(name, from) {\n  let dir = path.resolve(from);\n  while (dir !== path.dirname(dir)) {\n    let modulesPath = path.join(dir, 'node_modules', name);\n    if (fs.existsSync(modulesPath)) return true;\n    dir = path.dirname(dir);\n  }\n  return false;\n}\n\nif (!isModuleInstalled('my-module', __dirname)) {\n  console.error('Run: npm install my-module');\n}","typeGuard":null,"tryCatchPattern":"try {\n  let resolved = await packageManager.resolve(id, from, options);\n} catch (e) {\n  if (e.diagnostics?.[0]?.message?.includes('listed in package.json')) {\n    // Module declared but not installed — run install\n    console.error('Run npm/yarn/pnpm install first');\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always run `npm install` / `yarn install` / `pnpm install` after modifying package.json.","Use a pre-build script that verifies node_modules is up to date: `npm ls` or a lockfile check.","In CI, cache node_modules but always run install as a build step.","Avoid manual edits to node_modules — only use the package manager."],"tags":["package-manager","module-resolution","dependency-conflict","package-json","install"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}