{"record":{"id":"939212c7a876e39a","repo":"hcengineering/platform","slug":"unable-to-create-package-json-e-939212","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/net/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/net/common/scripts/install-run.js#L608-L644","documentation":"_createPackageJson writes a minimal package.json (name 'ci-rush', dependencies omitted, MIT license) into packageInstallFolder so npm can install the requested package. If fs.writeFileSync fails (or JSON serialization throws), the error is wrapped as 'Unable to create package.json: <cause>'.","triggerScenarios":"installAndRun → _createPackageJson, when the install folder is not writable (EACCES/EPERM), does not exist (ENOENT after a failed clean step), is on a full disk (ENOSPC), or the path is invalid/locked on Windows.","commonSituations":"Read-only CI workspace or cache directory; disk quota exceeded; the folder was deleted between the clean and write steps by a concurrent process; permissions broken by a previous sudo-invoked run.","solutions":["Check permissions and writability of the package install folder (and free disk space) before running.","Delete the rush temp/install folder and re-run so it is recreated cleanly.","Avoid concurrent install-run invocations sharing the same install folder.","If permissions were changed by running as root previously, fix ownership (chown) of the temp directory."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify the install folder is writable before running the script\nconst fs = require('fs');\nfs.mkdirSync(installFolder, { recursive: true });\nfs.accessSync(installFolder, fs.constants.W_OK);\nconst probe = require('path').join(installFolder, '.write-probe');\nfs.writeFileSync(probe, 'ok');\nfs.unlinkSync(probe);","typeGuard":null,"tryCatchPattern":"try {\n  runInstallRun();\n} catch (e) {\n  if (/Unable to create package\\.json/.test(e.message)) {\n    console.error(`Install folder not writable or full: ${e.message}`);\n    // clean and re-create the folder once\n    require('fs').rmSync(packageInstallFolder, { recursive: true, force: true });\n    runInstallRun();\n  } else throw e;\n}","preventionTips":["Ensure the rush temp/install folder is writable by the user running the script.","Monitor free disk space in CI before dependency install steps.","Fix ownership after any sudo-elevated runs in the same directory.","Avoid concurrent runs that could delete the folder mid-write."],"tags":["filesystem","package-json","permissions"],"backgroundTag":"file-write-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}