hcengineering/platform · error

Unable to resolve version ${version} of package ${name}: ${e

Error message

Unable to resolve version ${version} of package ${name}: ${e}

What it means

This is the outer catch of _resolvePackageVersion: any failure inside version resolution — the `npm view` spawn error (177), no matching versions (178), JSON.parse failure of npm output — is wrapped and rethrown as this message naming the package and version range, with the inner error appended.

Source

Thrown at foundations/server/common/scripts/install-run.js:525

            const npmViewVersionOutput = npmVersionSpawnResult.stdout.toString();
            const parsedVersionOutput = JSON.parse(npmViewVersionOutput);
            const versions = Array.isArray(parsedVersionOutput)
                ? parsedVersionOutput
                : [parsedVersionOutput];
            let latestVersion = versions[0];
            for (let i = 1; i < versions.length; i++) {
                const latestVersionCandidate = versions[i];
                if (_compareVersionStrings(latestVersionCandidate, latestVersion) > 0) {
                    latestVersion = latestVersionCandidate;
                }
            }
            if (!latestVersion) {
                throw new Error('No versions found for the specified version range.');
            }
            return latestVersion;
        }
        catch (e) {
            throw new Error(`Unable to resolve version ${version} of package ${name}: ${e}`);
        }
    }
}
let _rushJsonFolder;
/**
 * Find the absolute path to the folder containing rush.json
 */
function findRushJsonFolder() {
    if (!_rushJsonFolder) {
        let basePath = __dirname;
        let tempPath = __dirname;
        do {
            const testRushJsonPath = path__WEBPACK_IMPORTED_MODULE_3__.join(basePath, RUSH_JSON_FILENAME);
            if (fs__WEBPACK_IMPORTED_MODULE_1__.existsSync(testRushJsonPath)) {
                _rushJsonFolder = basePath;
                break;
            }
            else {

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Read the inner `: ${e}` part of the message to find the root cause first
  2. Fix the specific inner issue (network/auth/range) per the corresponding error's steps
  3. Run the npm view command manually to reproduce outside the script
  4. Ensure npm outputs clean JSON (remove plugins/config that print to stdout)

Example fix

// before
"pnpm@latest"
// after (pin a known-good version to avoid resolution entirely)
"pnpm@8.15.4"
Defensive patterns

Strategy: try-catch

Validate before calling

try {
  child_process.execSync(`npm view "${name}@${range}" version --json --no-update-notifier`, { stdio: [] });
} catch (e) {
  throw new Error(`Cannot resolve ${name}@${range}: ${e.message}`);
}

Type guard

null

Try / catch

try {
  runRushInstall();
} catch (e) {
  if (String(e).startsWith('Unable to resolve version')) {
    console.error('Inspect inner cause:', e.message); // then branch on network/auth/range
  } else throw e;
}

Prevention

When it happens

Trigger: Any cause of the inner errors: registry/network failure, auth failure, nonexistent package, no versions in range, or `npm view --json` returning non-JSON output (npm warnings/prompt text polluting stdout).

Common situations: Same as inner errors — offline CI, missing private-registry auth, typo'd package names, npm printing update-notifier noise into stdout breaking JSON.parse in older setups.

Related errors


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