{"record":{"id":"bd992009068b1d00","repo":"hcengineering/platform","slug":"error-cleaning-the-package-install-folder-packa-bd9920","errorCode":null,"errorMessage":"Error cleaning the package install folder (${packageInstallFolder}): ${e}","messagePattern":"Error cleaning the package install folder \\((.+?)\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"foundations/net/common/scripts/install-run.js","lineNumber":607,"sourceCode":"    try {\n        const flagFile = path__WEBPACK_IMPORTED_MODULE_3__.resolve(packageInstallFolder, INSTALLED_FLAG_FILENAME);\n        _deleteFile(flagFile);\n        const packageLockFile = path__WEBPACK_IMPORTED_MODULE_3__.resolve(packageInstallFolder, 'package-lock.json');\n        if (lockFilePath) {\n            fs__WEBPACK_IMPORTED_MODULE_1__.copyFileSync(lockFilePath, packageLockFile);\n        }\n        else {\n            // Not running `npm ci`, so need to cleanup\n            _deleteFile(packageLockFile);\n            const nodeModulesFolder = path__WEBPACK_IMPORTED_MODULE_3__.resolve(packageInstallFolder, NODE_MODULES_FOLDER_NAME);\n            if (fs__WEBPACK_IMPORTED_MODULE_1__.existsSync(nodeModulesFolder)) {\n                const rushRecyclerFolder = _ensureAndJoinPath(rushTempFolder, 'rush-recycler');\n                fs__WEBPACK_IMPORTED_MODULE_1__.renameSync(nodeModulesFolder, path__WEBPACK_IMPORTED_MODULE_3__.join(rushRecyclerFolder, `install-run-${Date.now().toString()}`));\n            }\n        }\n    }\n    catch (e) {\n        throw new Error(`Error cleaning the package install folder (${packageInstallFolder}): ${e}`);\n    }\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) {","sourceCodeStart":589,"sourceCodeEnd":625,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/net/common/scripts/install-run.js#L589-L625","documentation":"_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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure no other install-run/rush process is using the same temp folder (fix concurrency or give each job its own RUSH_TEMP_FOLDER).","Manually delete the stale install folder (or the whole rush temp/recycler directory) and re-run.","Check filesystem permissions on the temp/install folder and disk space; on Windows exclude the folder from AV/indexing.","Re-run after transient locks clear — the rename step is inherently racy under concurrent access."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Ensure the install folder is unlocked and writable before invoking\nconst fs = require('fs');\nconst os = require('os');\nconst path = require('path');\nconst tmp = process.env.RUSH_TEMP_FOLDER || path.join(os.tmpdir(), 'rush-temp');\nif (fs.existsSync(tmp)) {\n  fs.accessSync(tmp, fs.constants.W_OK);\n  if (process.platform === 'win32' && isDirLocked(tmp)) throw new Error('rush temp folder is locked by another process');\n}","typeGuard":null,"tryCatchPattern":"let attempt = 0;\nwhile (attempt < 3) {\n  try {\n    runInstallRun();\n    break;\n  } catch (e) {\n    if (/Error cleaning the package install folder/.test(e.message) && ++attempt < 3) {\n      require('fs').rmSync(rushTempFolder, { recursive: true, force: true }); // clear stale/locked folder\n      continue;\n    }\n    throw e;\n  }\n}","preventionTips":["Give each concurrent CI job its own RUSH_TEMP_FOLDER to avoid rename races.","Exclude the temp folder from antivirus/indexing on Windows.","Check disk space and permissions on the temp directory regularly.","Never run installs as root in a directory later used by non-root users."],"tags":["filesystem","concurrency","node-modules","windows"],"backgroundTag":"filesystem-rename-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}