xai-org/grok-build · error

npm view @{} returned empty version list

Error message

npm view @{} returned empty version list

What it means

fetch_npm_tag runs `npm view @<pkg> <tag>` and parses the JSON output; if the result is a JSON array with no string entries it throws this error, since no version could be extracted. It means npm answered, but the version list was empty — the tag/dist-tag resolved to nothing.

Source

Thrown at crates/codegen/xai-grok-update/src/version.rs:203

    cmd.args(&args).stdin(std::process::Stdio::null());
    xai_grok_tools::util::detach_command(&mut cmd);
    cmd.envs(xai_grok_tools::util::pager_env());
    let output = cmd.output().await?;

    if !output.status.success() {
        let stderr = String::from_utf8_lossy(&output.stderr);
        anyhow::bail!("npm view @{} failed: {}", tag, stderr.trim());
    }

    let stdout = String::from_utf8(output.stdout)?;
    let value: Value = serde_json::from_str(stdout.trim())?;
    match value {
        Value::String(version) => Ok(version),
        Value::Array(values) => values
            .iter()
            .rev()
            .find_map(|entry| entry.as_str().map(|item| item.to_string()))
            .ok_or_else(|| anyhow::anyhow!("npm view @{} returned empty version list", tag)),
        _ => anyhow::bail!("npm view @{} returned unexpected JSON", tag),
    }
}

/// Fetch the latest version from GitHub Releases using `gh release list`.
/// For alpha channel, fetches both pre-release and stable-only, returns the
/// semver-greater — `gh release list --limit 1` orders by publication date,
/// not semver, so we need both to guarantee correctness.
#[doc(hidden)]
pub async fn fetch_gh_release_version(channel: &str) -> Result<String> {
    if channel == "alpha" {
        let (with_pre, stable_only) = tokio::try_join!(
            fetch_gh_release_latest(false),
            fetch_gh_release_latest(true),
        )?;
        return semver_max(&with_pre, &stable_only);
    }
    fetch_gh_release_latest(true).await

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Verify the package and tag exist: run `npm view @<pkg> <tag>` manually
  2. Use a tag that resolves to published versions (e.g. "latest")
  3. Check npm registry configuration (.npmrc) — point at the correct public registry
  4. Retry after re-publishing if the package was just published
Defensive patterns

Strategy: fallback

Validate before calling

// pre-check that the tag resolves
let out = std::process::Command::new("npm")
    .args(["view", &format!("@{pkg}"), tag, "--json"])
    .output()?;
if out.stdout.trim() == "[]" || out.stdout.trim().is_empty() {
    anyhow::bail!("tag @{pkg} {tag} resolves to no versions");
}

Try / catch

match fetch_npm_tag(pkg, tag).await {
    Err(e) if e.to_string().contains("returned empty version list") => {
        // fall back to a known tag
        fetch_npm_tag(pkg, "latest").await
    }
    result => result,
}

Prevention

When it happens

Trigger: Calling fetch_npm_tag (via fetch_npm_version or the test helper) when `npm view` returns an empty array (Value::Array with no string items) for the requested tag — e.g. a dist-tag pointing at no versions or an unpublished package.

Common situations: Querying an npm tag that doesn't exist or was removed; a freshly published package whose dist-tags haven't propagated; private/registry-scoped packages where npm returns an empty list instead of an error; misconfigured registry mirror returning empty arrays.

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/bea4dc9b21f5bedc. Report an issue: GitHub.