{"record":{"id":"ad38f1299b7e1a6b","repo":"hcengineering/platform","slug":"unable-to-create-package-json-e-ad38f1","errorCode":null,"errorMessage":"Unable to create package.json: ${e}","messagePattern":"Unable to create package\\.json: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"foundations/utils/common/scripts/install-run.js","lineNumber":626,"sourceCode":"    }\n}\nfunction _createPackageJson(packageInstallFolder, name, version) {\n    try {\n        const packageJsonContents = {\n            name: 'ci-rush',\n            version: '0.0.0',\n            dependencies: {\n                [name]: version\n            },\n            description: \"DON'T WARN\",\n            repository: \"DON'T WARN\",\n            license: 'MIT'\n        };\n        const packageJsonPath = path__WEBPACK_IMPORTED_MODULE_3__.join(packageInstallFolder, PACKAGE_JSON_FILENAME);\n        fs__WEBPACK_IMPORTED_MODULE_1__.writeFileSync(packageJsonPath, JSON.stringify(packageJsonContents, undefined, 2));\n    }\n    catch (e) {\n        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`);","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/utils/common/scripts/install-run.js#L608-L644","documentation":"_createPackageJson writes a minimal package.json (name 'ci-rush', dependencies containing the target package) into the package install folder with writeFileSync. If the write fails, the error is rethrown as 'Unable to create package.json: ${e}'. Without this file npm install cannot set up the isolated package folder.","triggerScenarios":"writeFileSync on <packageInstallFolder>/package.json throws — read-only folder, disk full, path is a directory, or permission denied after _cleanInstallFolder partially succeeded.","commonSituations":"Read-only CI workspace mounts; disk quota exceeded on shared runners; packageInstallFolder existing as a file or with wrong ownership after a previous failed run.","solutions":["Ensure the package install folder is writable by the current user (fix ownership/permissions)","Free disk space / check quota","Delete the package install folder so it is recreated cleanly and re-run","Inspect the wrapped cause (`: ${e}`) for the exact fs error code"],"exampleFix":"// before\nls -l common/temp/install-run/packages   # owned by root\n// after\nsudo chown -R $(whoami) common/temp/install-run\nnode common/scripts/install-run.js pnpm install","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nconst path = require('path');\nconst pkgDir = path.join(tempDir, 'install-run', 'packages');\nfs.mkdirSync(pkgDir, { recursive: true });\nfs.accessSync(pkgDir, fs.constants.W_OK);\nconst pj = path.join(pkgDir, 'package.json');\nif (fs.existsSync(pj) && fs.statSync(pj).isDirectory()) {\n  throw new Error(`${pj} exists as a directory; remove it before rerunning`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  installAndRun(/* ... */);\n} catch (e) {\n  if (e.message.startsWith('Unable to create package.json')) {\n    fs.rmSync(pkgDir, { recursive: true, force: true });\n    return installAndRun(/* ... */);\n  }\n  throw e;\n}","preventionTips":["Ensure the CI workspace (including common/temp) is writable by the job user","Watch for disk-quota errors on shared runners","Remove leftover package install folders after failed runs"],"tags":["filesystem","package-json","permissions","write"],"backgroundTag":"file-write-permission-denied","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}