{"record":{"id":"386dd8c11dd135fe","repo":"hcengineering/platform","slug":"error-cleaning-the-package-install-folder-packa-386dd8","errorCode":null,"errorMessage":"Error cleaning the package install folder (${packageInstallFolder}): ${e}","messagePattern":"Error cleaning the package install folder \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"foundations/core/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/core/common/scripts/install-run.js#L589-L625","documentation":"_cleanInstallFolder prepares common/temp/install-run-<id> for a fresh install; if a stale install folder exists it moves node_modules into the rush-recycler folder via renameSync. Any filesystem failure during this cleanup (delete/rename of the package install folder) is rethrown wrapped as 'Error cleaning the package install folder (...)'.","triggerScenarios":"installAndRun detects an existing/incomplete install folder and tries to remove or rename it, but the OS call fails — e.g. EBUSY/EPERM because files are locked, EACCES from permissions, or ENOTEMPTY on the rename into rush-recycler.","commonSituations":"Parallel CI jobs sharing the same repo checkout (concurrent installs racing on common/temp); antivirus or a running dev server holding files in node_modules on Windows; read-only or quota-exceeded volumes; leftover root-owned files from a container run.","solutions":["Ensure no other process/CI job is using the same checkout; run installs serially or with separate workspaces.","Stop processes holding files open (dev servers, editors, antivirus scans) then delete common/temp manually.","Manually remove common/temp/install-run-* and rush-recycler contents with elevated permissions if needed.","Check filesystem permissions/free space on the volume hosting common/temp."],"exampleFix":"// before (retry on locked folder)\nnpx install-run-rush.js\n// after\nrm -rf common/temp/install-run-* common/temp/rush-recycler && npx install-run-rush.js","handlingStrategy":"try-catch","validationCode":"const fs = require('fs');\nfunction assertTempWritable(repoRoot) {\n  const temp = require('path').join(repoRoot, 'common', 'temp');\n  fs.mkdirSync(temp, { recursive: true });\n  fs.accessSync(temp, fs.constants.W_OK);\n}\nassertTempWritable(process.cwd());","typeGuard":"function isInstallFolderClean(folder) {\n  const fs = require('fs');\n  return !fs.existsSync(folder); // no stale folder to clean\n}","tryCatchPattern":"try {\n  installAndRun(logger, name, version, bin, args);\n} catch (e) {\n  if (/Error cleaning the package install folder/.test(e.message)) {\n    const fs = require('fs');\n    fs.rmSync('common/temp/install-run-*', { recursive: true, force: true });\n    return installAndRun(logger, name, version, bin, args); // one clean retry\n  }\n  throw e;\n}","preventionTips":["Run only one install/bootstrap per checkout at a time","Exclude common/temp from antivirus real-time scanning on CI agents","Verify disk space and write permissions before CI runs","Clean common/temp between pipeline stages"],"tags":["filesystem","npm-install","ci","windows"],"backgroundTag":"fs-cleanup-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}