{"record":{"id":"3199ffa9e754b012","repo":"hcengineering/platform","slug":"npm-command-encountered-an-error","errorCode":null,"errorMessage":"\"npm ${command}\" encountered an error","messagePattern":"\"npm (.+?)\" encountered an error","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"foundations/communication/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/communication/common/scripts/install-run.js#L626-L662","documentation":"Rush's install-run.js shim runs `npm install <name>@<version>` into a temp folder to provision a package tool on demand. If the spawned npm process exits with a non-zero status, this Error is thrown. It means npm itself completed (was found and executed) but the install failed, and the failure message was already streamed via stdio: 'inherit'.","triggerScenarios":"Running `node install-run.js <pkg>@<version> <bin>` (or install-run-rush.js) when the child `npm install` process exits non-zero — e.g. package/version not found in the registry, network/registry auth failure, or npm configured with a failing pre/post script.","commonSituations":"Typo in package name or version in a bootstrap script; corporate proxy or private registry blocking the fetch; npm scripts hook failing; out-of-disk space; Node/npm version mismatch producing engine errors.","solutions":["Read the npm output printed above the error (stdio is inherited) to find the underlying npm failure.","Verify the package name and version in the install-run invocation exist in the registry (`npm view <name>@<version>`).","Check network/registry access: run `npm config get registry`, and confirm proxy/.npmrc auth is configured.","Clear the cached install folder under common/temp (install-run uses a temp install dir) and retry.","Run the npm install manually in the same environment to reproduce and fix environment issues."],"exampleFix":"// before\nnode common/scripts/install-run.js qrcode@^1.2.0 qrcode -f x\n// Error: \"npm install\" encountered an error\n// after: fix the specifier to a resolvable version\nnode common/scripts/install-run.js qrcode@1.4.2 qrcode -f x","handlingStrategy":"try-catch","validationCode":"const spec = 'qrcode@^1.2.0'\nconst [name, version] = spec.split('@')\nconst res = await fetch(`https://registry.npmjs.org/${name}/${version}`)\nif (!res.ok) throw new Error(`Package ${spec} not resolvable in registry`)","typeGuard":null,"tryCatchPattern":"try {\n  await runBootstrap()\n} catch (e) {\n  if (String(e).includes('encountered an error')) {\n    console.error('npm install failed; check npm output above and registry access')\n  }\n  throw e\n}","preventionTips":["Pin exact, existing package versions in bootstrap scripts.","Verify registry/proxy connectivity and .npmrc auth in CI before bootstrapping.","Read the inherited npm output above the throw for the real cause.","Clear common/temp install folders when retrying after a failed install."],"tags":["npm","rush","install","subprocess","bootstrap"],"backgroundTag":"npm-install-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}