{"record":{"id":"c658a39a3935517a","repo":"parcel-bundler/parcel","slug":"npm-failed-to-install-modules-e-message-st","errorCode":null,"errorMessage":"npm failed to install modules: ${e.message} - ${stderr.join('\\n')}","messagePattern":"npm failed to install modules: (.+?) - (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/package-manager/src/Npm.js","lineNumber":80,"sourceCode":"        logger.log({\n          origin: '@parcel/package-manager',\n          message: `Added ${addedCount} packages via npm`,\n        });\n      }\n\n      // Since we succeeded, stderr might have useful information not included\n      // in the json written to stdout. It's also not necessary to log these as\n      // errors as they often aren't.\n      for (let message of stderr) {\n        if (message.length > 0) {\n          logger.log({\n            origin: '@parcel/package-manager',\n            message,\n          });\n        }\n      }\n    } catch (e) {\n      throw new Error(\n        'npm failed to install modules: ' +\n          e.message +\n          ' - ' +\n          stderr.join('\\n'),\n      );\n    }\n  }\n}\n\ntype NPMResults = {|\n  added: Array<{name: string, ...}>,\n|};\n\nregisterSerializableClass(`${pkg.version}:Npm`, Npm);\n","sourceCodeStart":62,"sourceCodeEnd":95,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/package-manager/src/Npm.js#L62-L95","documentation":"Thrown by the Npm package installer when the npm install subprocess fails (throws an exception caught in the try/catch). The error message concatenates the caught exception's message and the full stderr output from the npm process. The catch block wraps any error — JSON parse failure of npm output, subprocess crash, or npm's own exit code failure.","triggerScenarios":"install() is called on the Npm class, which spawns `npm install` as a child process. The child process exits non-zero, or the stdout JSON parsing throws. The catch block captures the exception and re-throws with the concatenated message including stderr lines.","commonSituations":"npm registry is unreachable or returns errors (network issues, corporate proxy, private registry auth failure). package.json references a non-existent package version. npm has insufficient permissions to write to node_modules. Disk full during install. npm cache corruption requiring `npm cache clean --force`.","solutions":["Read the stderr output in the error message — it contains npm's own diagnostic output.","Check network connectivity and registry access: `npm ping` or `npm config get registry`.","For private registries, verify authentication: `npm whoami` or check .npmrc.","Clear npm cache: `npm cache clean --force` then retry.","Check disk space and permissions on the project directory and node_modules."],"exampleFix":"// before: npm install fails with registry error\n// Error: npm failed to install modules: ...\n// - E404 Not Found - GET https://registry.npmjs.org/nonexistent-pkg\n\n// after: fix the package name or registry\n// $ npm config get registry  // verify correct registry\n// $ npm install  // retry after fixing package.json","handlingStrategy":"try-catch","validationCode":"// Pre-flight checks before npm install\nconst {execSync} = require('child_process');\n\nfunction preflightNpm() {\n  // Check registry connectivity\n  try {\n    execSync('npm ping', {stdio: 'pipe', timeout: 10000});\n  } catch {\n    throw new Error('npm registry unreachable — check network and proxy settings');\n  }\n  // Check disk space\n  let {execSync: es} = require('child_process');\n  let disk = es('df -k .', {encoding: 'utf8'});\n  // ... parse and validate\n}","typeGuard":null,"tryCatchPattern":"try {\n  await npmInstaller.install({modules, saveDev, cwd, packagePath, fs});\n} catch (e) {\n  if (e.message.startsWith('npm failed to install modules')) {\n    // Parse stderr from the error message for specific npm error codes\n    let stderr = e.message.split(' - ').slice(1).join(' - ');\n    if (stderr.includes('E404')) {\n      console.error('Package not found — check name in package.json');\n    } else if (stderr.includes('EACCES')) {\n      console.error('Permission denied — check npm prefix permissions');\n    } else {\n      console.error('npm install failed:', stderr);\n    }\n  } else {\n    throw e;\n  }\n}","preventionTips":["Run `npm install` manually first to surface errors before Parcel's auto-install triggers.","Ensure registry URL and auth tokens are configured in .npmrc.","Check disk space and permissions before running Parcel.","Use `npm cache verify` periodically to prevent cache corruption."],"tags":["package-manager","npm","install-failure","subprocess","network"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}