{"record":{"id":"4c60534e303fb224","repo":"hcengineering/platform","slug":"unable-to-create-installed-flag-file-in-packagei-4c6053","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/core/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/core/common/scripts/install-run.js#L660-L696","documentation":"_writeFlagFile records installed.flag (containing the Node version) in the package install folder so subsequent runs can skip reinstalling when the Node version is unchanged. If writeFileSync of that flag file fails, the error 'Unable to create installed.flag file in <folder>' is thrown. The install itself may have succeeded, but without the flag the fast-path can never trigger.","triggerScenarios":"writeFileSync of common/temp/install-run-*/installed.flag fails due to permissions (EACCES), read-only filesystem, disk full (ENOSPC), or the install folder being deleted/raced by another process between install and flag write.","commonSituations":"CI runners lacking write access to repo temp dirs; concurrent pipeline stages sharing a checkout; quota-limited or read-only volumes; Windows file locking after npm install finished but files still held.","solutions":["Fix write permissions on the package install folder (chmod/chown) for the invoking user.","Ensure no parallel process deletes or locks common/temp while the script runs.","Free disk space if ENOSPC.","Remove common/temp/install-run-* and rerun the bootstrap to regenerate the folder and flag."],"exampleFix":"// before (root-owned temp from a prior sudo run)\nnode common/scripts/install-run-rush.js\n// after\nsudo rm -rf common/temp/install-run-* && node common/scripts/install-run-rush.js","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction assertFlagWritable(folder) {\n  const probe = require('path').join(folder, '.write-probe');\n  fs.mkdirSync(folder, { recursive: true });\n  fs.writeFileSync(probe, 'ok');\n  fs.unlinkSync(probe);\n}\nassertFlagWritable('common/temp/install-run-probe');","typeGuard":"function canWriteTo(dir) {\n  const fs = require('fs');\n  try { fs.accessSync(dir, fs.constants.W_OK); return true; } catch { return false; }\n}","tryCatchPattern":"try {\n  installAndRun(logger, name, version, bin, args);\n} catch (e) {\n  if (/Unable to create installed\\.flag/.test(e.message)) {\n    const fs = require('fs');\n    fs.rmSync('common/temp/install-run-*', { recursive: true, force: true });\n    console.error('Install folder unwritable or raced; cleaned and aborting — rerun the bootstrap.');\n  }\n  throw e;\n}","preventionTips":["Ensure the CI user owns common/temp (avoid root-owned dirs from prior sudo runs)","Serialize bootstrap steps so no parallel job deletes the install folder mid-run","Monitor free disk space on build agents","Treat installed.flag as an optimization only — verify the install on failure"],"tags":["filesystem","flag-file","npm-install"],"backgroundTag":"flag-file-write-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}