{"record":{"id":"1165dee1d7794ea1","repo":"hcengineering/platform","slug":"unable-to-create-installed-flag-file-in-packagei-1165de","errorCode":null,"errorMessage":"Unable to create installed.flag file in ${packageInstallFolder}","messagePattern":"Unable to create installed\\.flag file in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"foundations/utils/common/scripts/install-run.js","lineNumber":678,"sourceCode":"/**\n * Returns a cross-platform path - windows must enclose any path containing spaces within double quotes.\n */\nfunction _getPlatformPath(platformPath) {\n    return _isWindows() && platformPath.includes(' ') ? `\"${platformPath}\"` : platformPath;\n}\nfunction _isWindows() {\n    return os__WEBPACK_IMPORTED_MODULE_2__.platform() === 'win32';\n}\n/**\n * Write a flag file to the package's install directory, signifying that the install was successful.\n */\nfunction _writeFlagFile(packageInstallFolder) {\n    try {\n        const flagFilePath = path__WEBPACK_IMPORTED_MODULE_3__.join(packageInstallFolder, INSTALLED_FLAG_FILENAME);\n        fs__WEBPACK_IMPORTED_MODULE_1__.writeFileSync(flagFilePath, process.version);\n    }\n    catch (e) {\n        throw new Error(`Unable to create installed.flag file in ${packageInstallFolder}`);\n    }\n}\nfunction installAndRun(logger, packageName, packageVersion, packageBinName, packageBinArgs, lockFilePath = process.env[INSTALL_RUN_LOCKFILE_PATH_VARIABLE]) {\n    const rushJsonFolder = findRushJsonFolder();\n    const rushCommonFolder = path__WEBPACK_IMPORTED_MODULE_3__.join(rushJsonFolder, 'common');\n    const rushTempFolder = _getRushTempFolder(rushCommonFolder);\n    const packageInstallFolder = _ensureAndJoinPath(rushTempFolder, 'install-run', `${packageName}@${packageVersion}`);\n    if (!_isPackageAlreadyInstalled(packageInstallFolder)) {\n        // The package isn't already installed\n        _cleanInstallFolder(rushTempFolder, packageInstallFolder, lockFilePath);\n        const sourceNpmrcFolder = path__WEBPACK_IMPORTED_MODULE_3__.join(rushCommonFolder, 'config', 'rush');\n        (0,_utilities_npmrcUtilities__WEBPACK_IMPORTED_MODULE_4__.syncNpmrc)({\n            sourceNpmrcFolder,\n            targetNpmrcFolder: packageInstallFolder,\n            logger,\n            supportEnvVarFallbackSyntax: false\n        });\n        _createPackageJson(packageInstallFolder, packageName, packageVersion);","sourceCodeStart":660,"sourceCodeEnd":696,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/utils/common/scripts/install-run.js#L660-L696","documentation":"install-run.js bootstraps a Rush repo by installing a tool package into a temp folder and writes an installed.flag file (containing the node version) to mark the package as installed. The flag write uses fs.writeFileSync inside a try/catch; any failure (permissions, missing folder, read-only disk) is converted into this opaque error. It guards against repeatedly attempting installs when the environment cannot support them.","triggerScenarios":"installAndRun resolves a package into packageInstallFolder and then calls _writeFlagFile; writeFileSync throws (e.g. common/temp exists but is not writable, disk full, antivirus lock, or the install folder was deleted between install and flag write).","commonSituations":"Running Rush-related scripts as a different user than the one who created common/temp; CI containers with read-only or restricted common/ directories; Node version changes conflicting with a stale or locked temp folder.","solutions":["Check write permissions on the <repo>/common/temp (or _getRushTempFolder) directory and fix ownership (chown/chmod).","Delete the rush temp folder (common/temp/install-run-* or similar) to clear stale state and retry.","Free disk space / close programs locking the folder (antivirus, editors).","Run the script with the same user/privileges that owns the repo checkout."],"exampleFix":"// before\nnpx install-run-rush install  // fails: Unable to create installed.flag file in ...\n// after\nrm -rf common/temp/install-run-*\nchmod u+w common/temp\nnpx install-run-rush install","handlingStrategy":"try-catch","validationCode":"const fs = require('fs')\nif (!fs.accessSync(tempFolder, fs.constants.W_OK)) throw new Error(`no write access to ${tempFolder}`)","typeGuard":null,"tryCatchPattern":"try {\n  await runInstallRunner()\n} catch (e) {\n  if (/Unable to create installed.flag/.test(e.message)) {\n    fs.rmSync(tempFolder, { recursive: true, force: true })\n    await runInstallRunner() // retry after clearing stale temp\n  } else throw e\n}","preventionTips":["Run repo scripts as the user who owns the checkout","Ensure common/temp is writable in CI images (no read-only mounts)","Clear common/temp when switching Node versions","Monitor disk space on build agents"],"tags":["filesystem","rush","permissions"],"backgroundTag":"filesystem-write-failure","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}