hcengineering/platform · error

Error syncing .npmrc file: ${e}

Error message

Error syncing .npmrc file: ${e}

What it means

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>'.

Source

Thrown at foundations/utils/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. Read the wrapped cause in the message and fix the underlying fs/permission/variable issue
  2. Ensure the source repo .npmrc exists and is readable, and the target location is writable
  3. Set any env vars referenced in .npmrc (e.g. NPM_TOKEN) before running the script
  4. Run with sufficient permissions or point npm cache/home to a writable path

Example fix

// before
npx install-run.js ...   // with .npmrc using ${NPM_TOKEN} unset
// after
export NPM_TOKEN=ghp_xxx
npx install-run.js ...
Defensive patterns

Strategy: try-catch

Validate before calling

const fs = require('fs')
function assertNpmrcSyncReady(sourceDir, targetDir) {
  const src = `${sourceDir}/.npmrc`
  if (fs.existsSync(src) && !fs.accessSync(src, fs.constants.R_OK) === false) {
    throw new Error(`${src} is not readable`)
  }
  fs.accessSync(targetDir, fs.constants.W_OK)
  for (const line of fs.existsSync(src) ? fs.readFileSync(src, 'utf8').split('\n') : []) {
    const m = line.match(/\$\{([A-Z0-9_]+)\}/)
    if (m && !process.env[m[1]]) throw new Error(`.npmrc variable ${m[1]} is not set`)
  }
}

Type guard

null

Try / catch

try {
  syncNpmrc(sourceDir, targetDir)
} catch (e) {
  if (String(e.message).startsWith('Error syncing .npmrc file:')) {
    console.error('npmrc sync failed; check .npmrc readability, target writability, and referenced env vars')
    console.error('Cause:', e.message)
  }
  throw e
}

Prevention

When it happens

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

Common situations: CI containers with read-only home directories; .npmrc containing ${NPM_TOKEN} that is unset; permission errors on ~/.npmrc; locked files on Windows.

Related errors


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