{"record":{"id":"a282f0f88e935d35","repo":"hcengineering/platform","slug":"npm-command-encountered-an-error-a282f0","errorCode":null,"errorMessage":"\"npm ${command}\" encountered an error","messagePattern":"\"npm (.+?)\" encountered an error","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"foundations/core/common/scripts/install-run.js","lineNumber":644,"sourceCode":"        throw new Error(`Unable to create package.json: ${e}`);\n    }\n}\n/**\n * Run \"npm install\" in the package install folder.\n */\nfunction _installPackage(logger, packageInstallFolder, name, version, command) {\n    try {\n        logger.info(`Installing ${name}...`);\n        const npmPath = getNpmPath();\n        const platformNpmPath = _getPlatformPath(npmPath);\n        const result = child_process__WEBPACK_IMPORTED_MODULE_0__.spawnSync(platformNpmPath, [command], {\n            stdio: 'inherit',\n            cwd: packageInstallFolder,\n            env: process.env,\n            shell: _isWindows()\n        });\n        if (result.status !== 0) {\n            throw new Error(`\"npm ${command}\" encountered an error`);\n        }\n        logger.info(`Successfully installed ${name}@${version}`);\n    }\n    catch (e) {\n        throw new Error(`Unable to install package: ${e}`);\n    }\n}\n/**\n * Get the \".bin\" path for the package.\n */\nfunction _getBinPath(packageInstallFolder, binName) {\n    const binFolderPath = path__WEBPACK_IMPORTED_MODULE_3__.resolve(packageInstallFolder, NODE_MODULES_FOLDER_NAME, '.bin');\n    const resolvedBinName = _isWindows() ? `${binName}.cmd` : binName;\n    return path__WEBPACK_IMPORTED_MODULE_3__.resolve(binFolderPath, resolvedBinName);\n}\n/**\n * Returns a cross-platform path - windows must enclose any path containing spaces within double quotes.\n */","sourceCodeStart":626,"sourceCodeEnd":662,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/core/common/scripts/install-run.js#L626-L662","documentation":"_installPackage spawns `npm install` (or similar command) synchronously in the package install folder; a non-zero exit status means npm itself failed. The library throws the plain message '\"npm <command>\" encountered an error' because npm's own output (inherited via stdio: 'inherit') carries the real diagnostics. Note the outer catch then rewraps this as error 45, so this message usually appears nested inside 'Unable to install package: ...'.","triggerScenarios":"The spawned npm process exits non-zero: unresolvable dependency tree, registry/network errors, invalid package.json in the install folder, npm not found (ENOENT on spawn), or unsupported npm flags for the installed npm version.","commonSituations":"Corporate proxy blocking the registry; incompatible lockfile (lockfileVersion mismatch with system npm); peer-dependency conflicts; disk space exhaustion; running an old npm that doesn't support flags like --frozen-lockfile.","solutions":["Read the npm output printed above the error (stdio is inherited) for the root cause.","Verify `npm --version` works and meets the script's expectations; update npm or Node if too old.","Check registry connectivity/proxy settings (`npm config get proxy`, `npm config get registry`).","Delete common/temp/install-run-* to force a clean reinstall, then rerun."],"exampleFix":"// before (failing npm)\nnpm install --frozen-lockfile  # old npm, unknown flag\n// after\nnpm install -g npm@latest && npm install --frozen-lockfile","handlingStrategy":"try-catch","validationCode":"const { execSync } = require('child_process');\nfunction assertNpmReady() {\n  const v = execSync('npm --version').toString().trim(); // throws if npm missing/broken\n  if (parseInt(v.split('.')[0], 10) < 7) throw new Error(`npm too old: ${v}`);\n}\nassertNpmReady();","typeGuard":null,"tryCatchPattern":"try {\n  installAndRun(logger, name, version, bin, args);\n} catch (e) {\n  if (/npm .* encountered an error|Unable to install package/.test(e.message)) {\n    // npm's real diagnostics were printed above via stdio: 'inherit'\n    console.error('npm install failed; see npm output above. Check registry access, lockfile, and npm version.');\n  }\n  throw e;\n}","preventionTips":["Read the inherited npm output above the error for the true cause","Pin a compatible npm/Node version in CI images","Verify registry and proxy settings on build agents","Do a clean reinstall (delete common/temp/install-run-*) after any npm config change"],"tags":["npm","child-process","npm-install","ci"],"backgroundTag":"npm-install-exit-nonzero","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}