{"record":{"id":"1c17c25f1507c82f","repo":"hcengineering/platform","slug":"error-cleaning-the-package-install-folder-packa-1c17c2","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/utils/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/utils/common/scripts/install-run.js#L589-L625","documentation":"_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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure no other npm/node process is using the same node_modules folder; kill stale CI or dev-server processes","Delete the stale node_modules (and the rush-recycler contents) manually and re-run","Check write permissions on the package install folder and the rush temp folder","Exclude the repo from antivirus/real-time scanning that locks files during rename"],"exampleFix":"// before: locked node_modules from a hung install\n// after: clean manually then retry\nrm -rf ~/.rush/install-run/node_modules common/temp/install-run/packages/node_modules\nnode common/scripts/install-run.js pnpm install","handlingStrategy":"try-catch","validationCode":"const fs = require('fs');\nconst path = require('path');\nconst installDir = path.join(process.env.RUSH_TEMP_FOLDER || path.join(repoRoot, 'common', 'temp'), 'install-run', 'packages');\nif (fs.existsSync(path.join(installDir, 'node_modules'))) {\n  console.warn('Stale node_modules present; delete it before rerunning if installs fail');\n}\nfs.accessSync(installDir, fs.constants.W_OK);","typeGuard":null,"tryCatchPattern":"try {\n  installAndRun(/* ... */);\n} catch (e) {\n  if (e.message.startsWith('Error cleaning the package install folder')) {\n    fs.rmSync(installDir, { recursive: true, force: true }); // clean slate\n    return installAndRun(/* ... */); // retry once\n  }\n  throw e;\n}","preventionTips":["Kill stale npm/node processes that hold locks on node_modules","Exclude the repo from antivirus real-time scanning","Ensure no two CI jobs share the same install folder concurrently"],"tags":["filesystem","cleanup","locked-files","node-modules"],"backgroundTag":"file-locked-cannot-rename","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}