hcengineering/platform · error
Unable to create package.json: ${e}
Error message
Unable to create package.json: ${e} What it means
_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.
Source
Thrown at foundations/utils/common/scripts/install-run.js:626
}
}
function _createPackageJson(packageInstallFolder, name, version) {
try {
const packageJsonContents = {
name: 'ci-rush',
version: '0.0.0',
dependencies: {
[name]: version
},
description: "DON'T WARN",
repository: "DON'T WARN",
license: 'MIT'
};
const packageJsonPath = path__WEBPACK_IMPORTED_MODULE_3__.join(packageInstallFolder, PACKAGE_JSON_FILENAME);
fs__WEBPACK_IMPORTED_MODULE_1__.writeFileSync(packageJsonPath, JSON.stringify(packageJsonContents, undefined, 2));
}
catch (e) {
throw new Error(`Unable to create package.json: ${e}`);
}
}
/**
* Run "npm install" in the package install folder.
*/
function _installPackage(logger, packageInstallFolder, name, version, command) {
try {
logger.info(`Installing ${name}...`);
const npmPath = getNpmPath();
const platformNpmPath = _getPlatformPath(npmPath);
const result = child_process__WEBPACK_IMPORTED_MODULE_0__.spawnSync(platformNpmPath, [command], {
stdio: 'inherit',
cwd: packageInstallFolder,
env: process.env,
shell: _isWindows()
});
if (result.status !== 0) {
throw new Error(`"npm ${command}" encountered an error`);View on GitHub (pinned to 63e28dc964)
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
Example fix
// before ls -l common/temp/install-run/packages # owned by root // after sudo chown -R $(whoami) common/temp/install-run node common/scripts/install-run.js pnpm install
Defensive patterns
Strategy: validation
Validate before calling
const fs = require('fs');
const path = require('path');
const pkgDir = path.join(tempDir, 'install-run', 'packages');
fs.mkdirSync(pkgDir, { recursive: true });
fs.accessSync(pkgDir, fs.constants.W_OK);
const pj = path.join(pkgDir, 'package.json');
if (fs.existsSync(pj) && fs.statSync(pj).isDirectory()) {
throw new Error(`${pj} exists as a directory; remove it before rerunning`);
} Try / catch
try {
installAndRun(/* ... */);
} catch (e) {
if (e.message.startsWith('Unable to create package.json')) {
fs.rmSync(pkgDir, { recursive: true, force: true });
return installAndRun(/* ... */);
}
throw e;
} Prevention
- 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
When it happens
Trigger: writeFileSync on <packageInstallFolder>/package.json throws — read-only folder, disk full, path is a directory, or permission denied after _cleanInstallFolder partially succeeded.
Common situations: 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.
Related errors
- Unable to create package.json: ${e}
- Error building local installation folder (${path__WEBPACK_IM
- Unable to create package.json: ${e}
- Unable to create installed.flag file in ${packageInstallFold
- Error building local installation folder (${path__WEBPACK_IM
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/ad38f1299b7e1a6b.
Report an issue: GitHub.