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 package install folder by removing stale node_modules: it renames an existing node_modules folder into the rush-recycler folder (or deletes it if the recycler folder already has too many entries). Any filesystem failure during this cleanup is wrapped in this error naming the package install folder.

Source

Thrown at foundations/utils/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 npm/node process is using the same node_modules folder; kill stale CI or dev-server processes
  2. Delete the stale node_modules (and the rush-recycler contents) manually and re-run
  3. Check write permissions on the package install folder and the rush temp folder
  4. Exclude the repo from antivirus/real-time scanning that locks files during rename

Example fix

// before: locked node_modules from a hung install
// after: clean manually then retry
rm -rf ~/.rush/install-run/node_modules common/temp/install-run/packages/node_modules
node common/scripts/install-run.js pnpm install
Defensive patterns

Strategy: try-catch

Validate before calling

const fs = require('fs');
const path = require('path');
const installDir = path.join(process.env.RUSH_TEMP_FOLDER || path.join(repoRoot, 'common', 'temp'), 'install-run', 'packages');
if (fs.existsSync(path.join(installDir, 'node_modules'))) {
  console.warn('Stale node_modules present; delete it before rerunning if installs fail');
}
fs.accessSync(installDir, fs.constants.W_OK);

Try / catch

try {
  installAndRun(/* ... */);
} catch (e) {
  if (e.message.startsWith('Error cleaning the package install folder')) {
    fs.rmSync(installDir, { recursive: true, force: true }); // clean slate
    return installAndRun(/* ... */); // retry once
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling installAndRun when the existing node_modules under packageInstallFolder cannot be renamed (renameSync fails) or the recycler folder cannot be ensured/created — e.g. files locked by another process, permission denied, or cross-device rename.

Common situations: A previous npm install still running and holding locks on node_modules; antivirus/backup software scanning node_modules during rename; read-only CI workspace from a cached volume; disk full preventing the recycler move.

Related errors


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