{"record":{"id":"7b03998b3b4d902f","repo":"hcengineering/platform","slug":"error-cleaning-the-package-install-folder-packa-7b0399","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/server/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/server/common/scripts/install-run.js#L589-L625","documentation":"During installAndRun, _cleanInstallFolder prepares the temporary package install folder by deleting installed.flag, copying/removing the lockfile, and moving any existing node_modules into a rush-recycler folder. If any of these filesystem operations fail (rename, copy, unlink), the underlying exception is wrapped and rethrown with the install folder path in the message.","triggerScenarios":"fs.copyFileSync fails because the lockFilePath (INSTALL_RUN_LOCKFILE_PATH_VARIABLE or argument) does not exist or is unreadable; fs.renameSync of node_modules fails because the rush-recycler folder cannot be created or the target path already exists; permission errors deleting installed.flag/package-lock.json.","commonSituations":"INSTALL_RUN_LOCKFILE_PATH_VARIABLE pointing to a wrong or missing path; read-only or disk-full rush temp folder (common/temp); leftover rush-recycler entries causing rename conflicts; permission issues on shared CI caches.","solutions":["Check that the lockfile path (env INSTALL_RUN_LOCKFILE_PATH_VARIABLE or lockFilePath arg) exists and is readable","Fix permissions on the rush temp folder (common/temp) and ensure the disk is not full","Delete common/temp/install-run and common/temp/rush-recycler leftovers, then retry the script","Re-run as a user with write access to the repo's common/temp directory"],"exampleFix":"// before\nINSTALL_RUN_LOCKFILE_PATH_VARIABLE=./missing/pnpm-lock.yaml node install-run.js ...\n// after\nls ./common/config/rush/pnpm-lock.yaml && INSTALL_RUN_LOCKFILE_PATH_VARIABLE=./common/config/rush/pnpm-lock.yaml node install-run.js ...","handlingStrategy":"try-catch","validationCode":"const fs = require('fs')\nif (process.env.INSTALL_RUN_LOCKFILE_PATH_VARIABLE && !fs.existsSync(process.env.INSTALL_RUN_LOCKFILE_PATH_VARIABLE)) {\n  throw new Error(`Lockfile not found: ${process.env.INSTALL_RUN_LOCKFILE_PATH_VARIABLE}`)\n}\nfs.accessSync('common/temp', fs.constants.W_OK)","typeGuard":null,"tryCatchPattern":"try {\n  installAndRun(logger, pkg, version, bin, args, lockFilePath)\n} catch (e) {\n  if (/^Error cleaning the package install folder/.test(e.message)) {\n    fs.rmSync('common/temp/install-run', { recursive: true, force: true })\n    installAndRun(logger, pkg, version, bin, args, lockFilePath)\n  } else throw e\n}","preventionTips":["Verify lockfile paths passed via INSTALL_RUN_LOCKFILE_PATH_VARIABLE exist","Keep common/temp writable and clear rush-recycler leftovers periodically","Avoid concurrent install-run runs against the same repo"],"tags":["rush","filesystem","npm","permissions"],"backgroundTag":"filesystem-operation-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}