{"record":{"id":"cfb7fbb4267ff531","repo":"hcengineering/platform","slug":"error-syncing-npmrc-file-e-cfb7fb","errorCode":null,"errorMessage":"Error syncing .npmrc file: ${e}","messagePattern":"Error syncing \\.npmrc file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"foundations/net/common/scripts/install-run.js","lineNumber":223,"sourceCode":"            // Ensure the target folder exists\n            if (!fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(targetNpmrcFolder)) {\n                fs__WEBPACK_IMPORTED_MODULE_0__.mkdirSync(targetNpmrcFolder, { recursive: true });\n            }\n            return _copyAndTrimNpmrcFile({\n                sourceNpmrcPath,\n                targetNpmrcPath,\n                logger,\n                ...options\n            });\n        }\n        else if (fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(targetNpmrcPath)) {\n            // If the source .npmrc doesn't exist and there is one in the target, delete the one in the target\n            logger.info(`Deleting ${targetNpmrcPath}`); // Verbose\n            fs__WEBPACK_IMPORTED_MODULE_0__.unlinkSync(targetNpmrcPath);\n        }\n    }\n    catch (e) {\n        throw new Error(`Error syncing .npmrc file: ${e}`);\n    }\n}\nfunction isVariableSetInNpmrcFile(sourceNpmrcFolder, variableKey, supportEnvVarFallbackSyntax) {\n    const sourceNpmrcPath = `${sourceNpmrcFolder}/.npmrc`;\n    //if .npmrc file does not exist, return false directly\n    if (!fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(sourceNpmrcPath)) {\n        return false;\n    }\n    const trimmedNpmrcFile = _trimNpmrcFile({ sourceNpmrcPath, supportEnvVarFallbackSyntax });\n    const variableKeyRegExp = new RegExp(`^${variableKey}=`, 'm');\n    return trimmedNpmrcFile.match(variableKeyRegExp) !== null;\n}\n//# sourceMappingURL=npmrcUtilities.js.map\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/net/common/scripts/install-run.js#L205-L241","documentation":"syncNpmrc() copies a source .npmrc into a target folder (creating or deleting as needed) and wraps any filesystem failure in this generic Error. It indicates the .npmrc sync step of the bootstrap failed — e.g. permission problems, missing folders, or unreadable source file.","triggerScenarios":"syncNpmrc(sourceNpmrcFolder, targetNpmrcFolder) is called and any fs operation inside the try block throws: reading the source .npmrc, writing/copying to the target, or unlinkSync on a stale target .npmrc.","commonSituations":"Read-only target directory (e.g. CI cache, mounted volume); source .npmrc missing while target exists and deletion fails; EACCES/EPERM from restrictive permissions; Windows file locks on the target .npmrc.","solutions":["Check filesystem permissions on both the source and target .npmrc paths and the containing folders.","Ensure the target folder exists and is writable before running the bootstrap (or create it manually).","Inspect the wrapped inner error (${e}) in the message to identify the exact fs operation that failed.","On Windows/CI, close processes locking the .npmrc or add retry/cleanup steps in the pipeline."],"exampleFix":"// before\nfs.mkdirSync(rushTempFolder, { recursive: true }) // missing -> EACCES later during syncNpmrc\n// after\nfs.mkdirSync(rushTempFolder, { recursive: true })\nfs.chmodSync(rushTempFolder, 0o755) // ensure writable before syncNpmrc","handlingStrategy":"try-catch","validationCode":"const src = `${sourceFolder}/.npmrc`, dst = `${targetFolder}/.npmrc`\nif (fs.existsSync(src) && !fs.accessSync(src, fs.constants.R_OK) === undefined) {}\nfs.accessSync(path.dirname(dst), fs.constants.W_OK) // throws early if target dir not writable","typeGuard":null,"tryCatchPattern":"try {\n  syncNpmrc(sourceFolder, targetFolder)\n} catch (e) {\n  console.error('npmrc sync failed; check permissions on', targetFolder, '\\ncause:', e.message)\n  process.exit(1)\n}","preventionTips":["Pre-create target folders with user-owned permissions before running bootstrap scripts.","Avoid running installs with sudo, which leaves root-owned .npmrc files behind.","On Windows, ensure no editor/AV locks .npmrc during CI.","Read the wrapped inner error in the message to identify which exact fs op failed."],"tags":["npm","filesystem","permissions"],"backgroundTag":"npmrc-sync-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}