{"record":{"id":"98d7e0a5d258faf4","repo":"hcengineering/platform","slug":"unable-to-create-installed-flag-file-in-packagei-98d7e0","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/net/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/net/common/scripts/install-run.js#L660-L696","documentation":"After npm install completes, _writeFlagFile writes an installed.flag file into the package install folder to mark it cached. If writeFileSync fails (permissions, full disk, read-only filesystem, missing directory), this error is thrown. It means the install succeeded or ran, but the cache marker could not be persisted.","triggerScenarios":"Running an install-run shim script when fs.writeFileSync cannot create installed.flag inside the rush temp package folder — e.g. directory owned by root/another user, read-only mount, or the folder was deleted mid-run.","commonSituations":"CI containers running as non-root but reusing a root-owned ~/.rush cache; Docker volumes mounted read-only; disk-quota exhaustion; multiple concurrent builds racing on the same temp folder.","solutions":["Check write permissions on the rush temp/common install folder and fix ownership (chown/chmod) or run as a user who can write there.","Delete the stale package install folder and re-run so it is recreated with correct permissions.","Free disk space if the volume is full.","Avoid running concurrent builds that share the same rush cache folder, or point INSTALL_RUN_LOCKFILE_PATH / cache to a writable location."],"exampleFix":"// before: ~/.rush owned by root, build runs as ci user\nsudo chown -R $(whoami) ~/.rush\nnode common/scripts/install-run-rush.js build\n// after: cache writable by the build user, script succeeds","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction cacheFolderWritable(folder) {\n  try { fs.mkdirSync(folder, { recursive: true }); fs.accessSync(folder, fs.constants.W_OK); return true; }\n  catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runInstallRunScript(args);\n} catch (e) {\n  if (String(e.message).startsWith('Unable to create installed.flag')) {\n    const folder = e.message.match(/in (.+)$/)?.[1];\n    console.error(`Cannot write to ${folder}: check permissions/disk space`);\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Run builds as a user that owns the rush cache folder (~/.rush).","Never mount the cache directory read-only.","Monitor disk space on CI runners.","Avoid concurrent builds sharing one rush temp folder."],"tags":["filesystem","permissions","rush","install"],"backgroundTag":"permission-denied","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}