{"record":{"id":"b6e672854d00fb6c","repo":"hcengineering/platform","slug":"error-syncing-npmrc-file-e-b6e672","errorCode":null,"errorMessage":"Error syncing .npmrc file: ${e}","messagePattern":"Error syncing \\.npmrc file: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"foundations/core/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/core/common/scripts/install-run.js#L205-L241","documentation":"syncNpmrc copies or deletes the repo's .npmrc (e.g. copying it into the Rush temp/common folder so installs pick up registry auth). Any filesystem failure during that sync — reading, copying, checking variables, or deleting the target .npmrc — is caught and rethrown wrapped in this error.","triggerScenarios":"Running install-run-rush/install-run scripts when the source .npmrc is unreadable, the target folder is not writable, an existing target .npmrc cannot be deleted, or an environment variable referenced in .npmrc is missing while syncing.","commonSituations":"CI checkout without repository secrets so .npmrc references undefined env vars; permission issues in the shared Rush folder; stale .npmrc in rush temp folder that cannot be removed.","solutions":["Check the wrapped cause `e` in the message to find the underlying fs error (ENOENT/EACCES/etc.) and fix that path/permission","Ensure the repository-root .npmrc exists and is readable, or remove it intentionally","Verify environment variables referenced in .npmrc (e.g. ${NPM_TOKEN}) are set in your shell/CI","Fix write permissions on the rush common/temp folder (or set RUSH_TEMP_FOLDER to a writable path)"],"exampleFix":"// before (.npmrc)\nregistry=https://registry.npmjs.org/\n//_authToken=${NPM_TOKEN}\n// after\nexport NPM_TOKEN=... before running, or remove the authToken line if using a public registry","handlingStrategy":"try-catch","validationCode":"const src = `${repoRoot}/.npmrc`;\nif (fs.existsSync(src) && !fs.accessSync(src, fs.constants.R_OK)) console.log('.npmrc readable');\nfor (const m of fs.readFileSync(src, 'utf8').match(/\\$\\{([A-Z0-9_]+)\\}/g) || []) {\n  const v = m.slice(2, -1);\n  if (!process.env[v]) console.warn(`Missing env var used by .npmrc: ${v}`);\n}","typeGuard":null,"tryCatchPattern":"try { syncNpmrc(from, to); }\ncatch (e) { if (/Error syncing .npmrc file/.test(e.message)) { console.error('Check .npmrc readability, target-folder permissions, and env vars:', e.message); } else throw e; }","preventionTips":["Keep .npmrc env-var references minimal and documented","Ensure CI exports all tokens referenced by .npmrc before rush scripts run","Grant write permission to the rush common/temp folder"],"tags":["npmrc","filesystem","config-sync"],"backgroundTag":"npmrc-sync-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}