{"record":{"id":"d76b817402c83f71","repo":"hcengineering/platform","slug":"error-syncing-npmrc-file-e-d76b81","errorCode":null,"errorMessage":"Error syncing .npmrc file: ${e}","messagePattern":"Error syncing \\.npmrc file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"foundations/utils/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/utils/common/scripts/install-run.js#L205-L241","documentation":"syncNpmrc in install-run.js copies or reconciles the repository's .npmrc into a target folder (typically the npm cache/home). Any failure during that sync — missing source file handling, unlink/copy errors, env-var expansion issues — is caught and rethrown wrapped as 'Error syncing .npmrc file: <cause>'.","triggerScenarios":"Running install-run.js when the source .npmrc is unreadable/malformed, the target .npmrc cannot be written or deleted (permissions, read-only fs), or an environment-variable referenced in .npmrc cannot be resolved.","commonSituations":"CI containers with read-only home directories; .npmrc containing ${NPM_TOKEN} that is unset; permission errors on ~/.npmrc; locked files on Windows.","solutions":["Read the wrapped cause in the message and fix the underlying fs/permission/variable issue","Ensure the source repo .npmrc exists and is readable, and the target location is writable","Set any env vars referenced in .npmrc (e.g. NPM_TOKEN) before running the script","Run with sufficient permissions or point npm cache/home to a writable path"],"exampleFix":"// before\nnpx install-run.js ...   // with .npmrc using ${NPM_TOKEN} unset\n// after\nexport NPM_TOKEN=ghp_xxx\nnpx install-run.js ...","handlingStrategy":"try-catch","validationCode":"const fs = require('fs')\nfunction assertNpmrcSyncReady(sourceDir, targetDir) {\n  const src = `${sourceDir}/.npmrc`\n  if (fs.existsSync(src) && !fs.accessSync(src, fs.constants.R_OK) === false) {\n    throw new Error(`${src} is not readable`)\n  }\n  fs.accessSync(targetDir, fs.constants.W_OK)\n  for (const line of fs.existsSync(src) ? fs.readFileSync(src, 'utf8').split('\\n') : []) {\n    const m = line.match(/\\$\\{([A-Z0-9_]+)\\}/)\n    if (m && !process.env[m[1]]) throw new Error(`.npmrc variable ${m[1]} is not set`)\n  }\n}","typeGuard":"null","tryCatchPattern":"try {\n  syncNpmrc(sourceDir, targetDir)\n} catch (e) {\n  if (String(e.message).startsWith('Error syncing .npmrc file:')) {\n    console.error('npmrc sync failed; check .npmrc readability, target writability, and referenced env vars')\n    console.error('Cause:', e.message)\n  }\n  throw e\n}","preventionTips":["Export all env vars referenced in .npmrc (e.g. NPM_TOKEN) before running install scripts","In CI, ensure HOME/npm cache points to a writable directory","Keep a checked-in minimal .npmrc and test its sync in CI"],"tags":["npm","npmrc","filesystem"],"backgroundTag":"npmrc-sync-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}