hcengineering/platform · error · 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', 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.

Source

Thrown at foundations/core/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

  1. Check write permissions on common/temp and fix them (chown/chmod) for the user running the script.
  2. Free disk space if the volume is full (ENOSPC).
  3. Delete stale common/temp/install-run-* folders and rerun so the folder is recreated fresh.
  4. Run the script as a user with write access to the repo (avoid sudo-created root-owned temp dirs).

Example fix

// before
node common/scripts/install-run-rush.js
// after
sudo chown -R $(whoami) common/temp && node common/scripts/install-run-rush.js
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
function assertCanWriteTo(folder) {
  fs.mkdirSync(folder, { recursive: true });
  fs.accessSync(folder, fs.constants.W_OK); // throws EACCES before npm/bootstrap starts
  const stat = fs.statfsSync(folder); // Node 18.15+
  if (stat.bavail * stat.bsize < 100 * 1024 * 1024) throw new Error('Less than 100MB free on volume');
}
assertCanWriteTo('common/temp/install-run-probe');

Type guard

function isWritableDir(p) {
  const fs = require('fs');
  try { fs.accessSync(p, fs.constants.W_OK); return fs.statSync(p).isDirectory(); } catch { return false; }
}

Try / catch

try {
  installAndRun(logger, name, version, bin, args);
} catch (e) {
  if (/Unable to create package\.json/.test(e.message)) {
    console.error('Check permissions and free space on common/temp, clean it, and retry.');
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/702c734dc42e0146. Report an issue: GitHub.