hcengineering/platform · error · Error

Error syncing .npmrc file: ${e}

Error message

Error syncing .npmrc file: ${e}

What it means

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.

Source

Thrown at foundations/core/common/scripts/install-run.js:223

            // Ensure the target folder exists
            if (!fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(targetNpmrcFolder)) {
                fs__WEBPACK_IMPORTED_MODULE_0__.mkdirSync(targetNpmrcFolder, { recursive: true });
            }
            return _copyAndTrimNpmrcFile({
                sourceNpmrcPath,
                targetNpmrcPath,
                logger,
                ...options
            });
        }
        else if (fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(targetNpmrcPath)) {
            // If the source .npmrc doesn't exist and there is one in the target, delete the one in the target
            logger.info(`Deleting ${targetNpmrcPath}`); // Verbose
            fs__WEBPACK_IMPORTED_MODULE_0__.unlinkSync(targetNpmrcPath);
        }
    }
    catch (e) {
        throw new Error(`Error syncing .npmrc file: ${e}`);
    }
}
function isVariableSetInNpmrcFile(sourceNpmrcFolder, variableKey, supportEnvVarFallbackSyntax) {
    const sourceNpmrcPath = `${sourceNpmrcFolder}/.npmrc`;
    //if .npmrc file does not exist, return false directly
    if (!fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(sourceNpmrcPath)) {
        return false;
    }
    const trimmedNpmrcFile = _trimNpmrcFile({ sourceNpmrcPath, supportEnvVarFallbackSyntax });
    const variableKeyRegExp = new RegExp(`^${variableKey}=`, 'm');
    return trimmedNpmrcFile.match(variableKeyRegExp) !== null;
}
//# sourceMappingURL=npmrcUtilities.js.map

/***/ })

/******/ 	});
/************************************************************************/

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Check the wrapped cause `e` in the message to find the underlying fs error (ENOENT/EACCES/etc.) and fix that path/permission
  2. Ensure the repository-root .npmrc exists and is readable, or remove it intentionally
  3. Verify environment variables referenced in .npmrc (e.g. ${NPM_TOKEN}) are set in your shell/CI
  4. Fix write permissions on the rush common/temp folder (or set RUSH_TEMP_FOLDER to a writable path)

Example fix

// before (.npmrc)
registry=https://registry.npmjs.org/
//_authToken=${NPM_TOKEN}
// after
export NPM_TOKEN=... before running, or remove the authToken line if using a public registry
Defensive patterns

Strategy: try-catch

Validate before calling

const src = `${repoRoot}/.npmrc`;
if (fs.existsSync(src) && !fs.accessSync(src, fs.constants.R_OK)) console.log('.npmrc readable');
for (const m of fs.readFileSync(src, 'utf8').match(/\$\{([A-Z0-9_]+)\}/g) || []) {
  const v = m.slice(2, -1);
  if (!process.env[v]) console.warn(`Missing env var used by .npmrc: ${v}`);
}

Try / catch

try { syncNpmrc(from, to); }
catch (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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/b6e672854d00fb6c. Report an issue: GitHub.