hcengineering/platform · error

Error cleaning the package install folder (${packageInstallF

Error message

Error cleaning the package install folder (${packageInstallFolder}): ${e}

What it means

_cleanInstallFolder prepares the shared package install folder under the rush temp directory; if the target node_modules exists it is renamed into a 'rush-recycler' folder via fs.renameSync. Any filesystem failure during this cleanup (rename/mkdir/renameSync errors) is wrapped and rethrown with the offending packageInstallFolder path and the cause. This prevents continuing with a stale or locked install folder.

Source

Thrown at foundations/net/common/scripts/install-run.js:607

    try {
        const flagFile = path__WEBPACK_IMPORTED_MODULE_3__.resolve(packageInstallFolder, INSTALLED_FLAG_FILENAME);
        _deleteFile(flagFile);
        const packageLockFile = path__WEBPACK_IMPORTED_MODULE_3__.resolve(packageInstallFolder, 'package-lock.json');
        if (lockFilePath) {
            fs__WEBPACK_IMPORTED_MODULE_1__.copyFileSync(lockFilePath, packageLockFile);
        }
        else {
            // Not running `npm ci`, so need to cleanup
            _deleteFile(packageLockFile);
            const nodeModulesFolder = path__WEBPACK_IMPORTED_MODULE_3__.resolve(packageInstallFolder, NODE_MODULES_FOLDER_NAME);
            if (fs__WEBPACK_IMPORTED_MODULE_1__.existsSync(nodeModulesFolder)) {
                const rushRecyclerFolder = _ensureAndJoinPath(rushTempFolder, 'rush-recycler');
                fs__WEBPACK_IMPORTED_MODULE_1__.renameSync(nodeModulesFolder, path__WEBPACK_IMPORTED_MODULE_3__.join(rushRecyclerFolder, `install-run-${Date.now().toString()}`));
            }
        }
    }
    catch (e) {
        throw new Error(`Error cleaning the package install folder (${packageInstallFolder}): ${e}`);
    }
}
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) {

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Ensure no other install-run/rush process is using the same temp folder (fix concurrency or give each job its own RUSH_TEMP_FOLDER).
  2. Manually delete the stale install folder (or the whole rush temp/recycler directory) and re-run.
  3. Check filesystem permissions on the temp/install folder and disk space; on Windows exclude the folder from AV/indexing.
  4. Re-run after transient locks clear — the rename step is inherently racy under concurrent access.
Defensive patterns

Strategy: retry

Validate before calling

// Ensure the install folder is unlocked and writable before invoking
const fs = require('fs');
const os = require('os');
const path = require('path');
const tmp = process.env.RUSH_TEMP_FOLDER || path.join(os.tmpdir(), 'rush-temp');
if (fs.existsSync(tmp)) {
  fs.accessSync(tmp, fs.constants.W_OK);
  if (process.platform === 'win32' && isDirLocked(tmp)) throw new Error('rush temp folder is locked by another process');
}

Try / catch

let attempt = 0;
while (attempt < 3) {
  try {
    runInstallRun();
    break;
  } catch (e) {
    if (/Error cleaning the package install folder/.test(e.message) && ++attempt < 3) {
      require('fs').rmSync(rushTempFolder, { recursive: true, force: true }); // clear stale/locked folder
      continue;
    }
    throw e;
  }
}

Prevention

When it happens

Trigger: installAndRun calls _cleanInstallFolder; the catch fires when fs operations on packageInstallFolder fail: EPERM/EACCES on rename, EBUSY because another process (concurrent install-run invocation, antivirus, editor) holds node_modules open, cross-device rename (EXDEV), or the rush-recycler path cannot be created.

Common situations: Two CI jobs sharing the same rush temp folder running install-run concurrently; Windows file locking by an indexer/AV scanning node_modules during rename; a read-only or full disk; leftover permissions issues from a previous sudo run.

Related errors


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