{"record":{"id":"6e39dbfab0f66dd6","repo":"hcengineering/platform","slug":"npm-command-encountered-an-error-6e39db","errorCode":null,"errorMessage":"\"npm ${command}\" encountered an error","messagePattern":"\"npm (.+?)\" encountered an error","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"foundations/net/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/net/common/scripts/install-run.js#L626-L662","documentation":"_installPackage spawns 'npm install' (or another package manager command) with stdio 'inherit' in the package install folder and checks the exit code; a non-zero status means npm failed, so the generic message '\"npm <command>\" encountered an error' is thrown. Since output is inherited, the actual npm failure details appear in the console immediately before this error.","triggerScenarios":"installAndRun → _installPackage, when the child npm process exits non-zero: registry unreachable/unauthorized, network timeouts, package/version not found in the registry, incompatible peer dependencies, or npm itself crashing.","commonSituations":"CI runners without npm credentials for a private registry; offline/air-gapped environments; proxy/firewall blocking registry.npmjs.org; corrupted npm cache; the pinned package version no longer existing.","solutions":["Read the npm output above this error — it contains the real cause; fix that (404, ETIMEDOUT, E401, ERESOLVE, etc.).","Verify registry connectivity and authentication (.npmrc / NODE_AUTH_TOKEN) in the environment running the script.","Re-run after transient network failures; clear a suspect npm cache ('npm cache clean --force') or set a working proxy.","Confirm the requested package@version is publishable/resolvable ('npm view <name>@<version>')."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-check registry reachability and auth before invoking\nconst { execSync } = require('child_process');\ntry {\n  execSync('npm ping', { stdio: 'ignore' });\n  execSync(`npm view ${name}@${version} version`, { stdio: 'ignore' });\n} catch (e) {\n  throw new Error(`Registry or package unreachable before install: ${e.message}`);\n}","typeGuard":null,"tryCatchPattern":"let attempts = 3;\nwhile (attempts--) {\n  try {\n    runInstallRun(name, version);\n    break;\n  } catch (e) {\n    if (/\"npm .*\" encountered an error/.test(e.message) && attempts > 0 && isTransient(e)) continue;\n    console.error(e.message + '\\nSee npm output above for the real failure.');\n    process.exit(1);\n  }\n}","preventionTips":["Configure .npmrc auth tokens and proxies in CI before the install step.","Use 'npm ping' / 'npm view' as a preflight connectivity check.","Cache node_modules or the npm cache to reduce network flakiness.","Always read the inherited npm output above the error — the message itself is generic by design."],"tags":["npm","install","network","ci"],"backgroundTag":"npm-install-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}