{"record":{"id":"a6167583917278fb","repo":"hcengineering/platform","slug":"unable-to-create-installed-flag-file-in-packagei","errorCode":null,"errorMessage":"Unable to create installed.flag file in ${packageInstallFolder}","messagePattern":"Unable to create installed\\.flag file in (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"foundations/communication/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/communication/common/scripts/install-run.js#L660-L696","documentation":"After installing a package, install-run.js writes an installed.flag file (containing the Node version) into the package install folder so subsequent runs can skip reinstalling. If writeFileSync fails, this Error is thrown. The package may actually be installed, but the shim cannot mark it as done.","triggerScenarios":"Running any install-run bootstrap where fs.writeFileSync cannot create installed.flag in the rush temp package folder — read-only directory, permission denied, path missing, or antivirus/file locking on Windows.","commonSituations":"CI containers running as non-root with a read-only repo mount; Docker images with restricted write access to common/temp; concurrent builds racing over the same temp folder; full disk.","solutions":["Ensure the rush common/temp directory (and package install folder) is writable by the current user.","Remove stale/partial temp install folders and re-run the bootstrap.","Check disk space (ENOSPC) and antivirus/file-lock interference if on Windows.","Run the script with elevated permissions only if the mount is intentionally restricted — otherwise fix mount options (e.g. don't mount repo read-only during bootstrap)."],"exampleFix":"// before\ndocker run -v $PWD:/repo:ro node:18 /repo/common/scripts/install-run-rush.js install\n// Error: Unable to create installed.flag file in ...\n// after\n// mount writable\ndocker run -v $PWD:/repo node:18 /repo/common/scripts/install-run-rush.js install","handlingStrategy":"validation","validationCode":"const fs = require('fs')\nconst tempDir = 'common/temp'\nfs.accessSync(tempDir, fs.constants.W_OK) // throws early if not writable","typeGuard":null,"tryCatchPattern":"try {\n  runInstallRun()\n} catch (e) {\n  if (String(e).includes('installed.flag')) {\n    console.error('Temp dir not writable or disk full; fix permissions and retry')\n  }\n  throw e\n}","preventionTips":["Mount repository volumes read-write in CI/Docker when bootstrapping.","Run scripts as a user with write access to common/temp.","Monitor disk space on build agents.","Exclude the temp folder from antivirus scanning on Windows."],"tags":["filesystem","rush","install","permissions","flag-file"],"backgroundTag":"file-write-permission-denied","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}