{"record":{"id":"702c734dc42e0146","repo":"hcengineering/platform","slug":"unable-to-create-package-json-e-702c73","errorCode":null,"errorMessage":"Unable to create package.json: ${e}","messagePattern":"Unable to create package\\.json: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"foundations/core/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/core/common/scripts/install-run.js#L608-L644","documentation":"_createPackageJson writes a minimal package.json (name 'ci-rush', MIT license) into the package install folder so npm install has a project root. If writeFileSync fails, the error is rethrown as 'Unable to create package.json'. This aborts the bootstrap because npm cannot install into a folder without a package.json.","triggerScenarios":"writeFileSync to common/temp/install-run-*/package.json fails due to EACCES/EPERM permissions, read-only filesystem, ENOSPC disk full, or the target folder not existing/was deleted between creation and write.","commonSituations":"CI runners with restricted write permissions to the repo's common/temp; disk-quota or full-disk environments; another process removing the temp folder mid-install; read-only container filesystems.","solutions":["Check write permissions on common/temp and fix them (chown/chmod) for the user running the script.","Free disk space if the volume is full (ENOSPC).","Delete stale common/temp/install-run-* folders and rerun so the folder is recreated fresh.","Run the script as a user with write access to the repo (avoid sudo-created root-owned temp dirs)."],"exampleFix":"// before\nnode common/scripts/install-run-rush.js\n// after\nsudo chown -R $(whoami) common/temp && node common/scripts/install-run-rush.js","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction assertCanWriteTo(folder) {\n  fs.mkdirSync(folder, { recursive: true });\n  fs.accessSync(folder, fs.constants.W_OK); // throws EACCES before npm/bootstrap starts\n  const stat = fs.statfsSync(folder); // Node 18.15+\n  if (stat.bavail * stat.bsize < 100 * 1024 * 1024) throw new Error('Less than 100MB free on volume');\n}\nassertCanWriteTo('common/temp/install-run-probe');","typeGuard":"function isWritableDir(p) {\n  const fs = require('fs');\n  try { fs.accessSync(p, fs.constants.W_OK); return fs.statSync(p).isDirectory(); } catch { return false; }\n}","tryCatchPattern":"try {\n  installAndRun(logger, name, version, bin, args);\n} catch (e) {\n  if (/Unable to create package\\.json/.test(e.message)) {\n    console.error('Check permissions and free space on common/temp, clean it, and retry.');\n  }\n  throw e;\n}","preventionTips":["Run CI scripts as a user with write access to the repo","Keep adequate free disk space on build agents","Avoid sudo-created root-owned common/temp folders","Clean stale common/temp/install-run-* directories regularly"],"tags":["filesystem","npm-install","permissions"],"backgroundTag":"package-json-write-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}