{"record":{"id":"85de5f6cdcbd5471","repo":"hcengineering/platform","slug":"npm-command-encountered-an-error-85de5f","errorCode":null,"errorMessage":"\"npm ${command}\" encountered an error","messagePattern":"\"npm (.+?)\" encountered an error","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"foundations/utils/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/utils/common/scripts/install-run.js#L626-L662","documentation":"_installPackage spawns `npm <command>` (typically 'install') in the package install folder with stdio inherit. If the spawned npm exits with a non-zero status, it throws '\"npm ${command}\" encountered an error'. This signals the npm subprocess itself failed; the real npm output is shown above this message because stdio is inherited.","triggerScenarios":"spawnSync(npmPath, [command, ...], {cwd: packageInstallFolder}) returns status !== 0 during installAndRun — npm install of the requested package failed for network, registry-auth, peer-conflict, or platform reasons.","commonSituations":"Corporate proxies blocking registry access; engine incompatibility (package requires different Node); ERESOLVE peer dependency conflicts; npm cache corruption (EACCES in ~/.npm).","solutions":["Read the full npm output printed before this error — it contains the actual failure (ERESOLVE, 404, network)","Fix network/proxy settings (HTTP_PROXY/HTTPS_PROXY, .npmrc registry) and retry","Clear the npm cache if it is corrupted: `npm cache clean --force`","Choose a package version compatible with your Node engine and dependency tree"],"exampleFix":"// before: proxy not configured in CI\n// after\nenv:\n  HTTP_PROXY: http://proxy.corp:8080\n  HTTPS_PROXY: http://proxy.corp:8080\nnode common/scripts/install-run.js pnpm install","handlingStrategy":"retry","validationCode":"const { execSync } = require('child_process');\nfunction preflightNpmInstall(name, version) {\n  execSync(`npm view ${name}@${version} version`, { stdio: 'inherit' }); // reachable registry + existing version\n}\npreflightNpmInstall('pnpm', '9.15.0');","typeGuard":null,"tryCatchPattern":"try {\n  installAndRun(logger, packageDir, name, version, command);\n} catch (e) {\n  if (e.message.includes('encountered an error')) {\n    console.error('npm install failed; see npm output above for the real cause (ERESOLVE, 404, network)');\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Always read the npm output printed above the error — stdio is inherited","Configure proxy/auth env vars in CI before installing","Keep the npm cache healthy (`npm cache verify`)","Pick versions compatible with your Node engine"],"tags":["npm","install","subprocess","network"],"backgroundTag":"npm-install-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}