jackwener/OpenCLI · warning · EmptyResultError

npm package

Error message

npm package

What it means

Thrown by the `npm package` command when the registry returns packument JSON for the name but there is no `dist-tags.latest` entry (or the tag is falsy). Without a latest version the command cannot render a per-version summary, so it raises EmptyResultError. This occurs for names that exist in the registry but have no publishable latest release.

Source

Thrown at clis/npm/package.js:48

    name: 'package',
    access: 'read',
    description: 'Single npm package metadata (latest version, license, homepage, repository). Use `npm downloads` for stats.',
    domain: 'registry.npmjs.org',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [
        { name: 'name', positional: true, required: true, help: 'npm package name (e.g. "react", "@vercel/og")' },
    ],
    columns: [
        'name', 'latestVersion', 'description', 'license', 'homepage', 'repository',
        'bugs', 'maintainers', 'keywords', 'created', 'modified', 'url',
    ],
    func: async (args) => {
        const name = requirePackageName(args.name);
        const body = await npmFetch(`${NPM_REGISTRY}/${name.split('/').map(encodeURIComponent).join('/')}`, `npm package ${name}`);
        const latest = body?.['dist-tags']?.latest;
        if (!latest) {
            throw new EmptyResultError('npm package', `npm registry has no latest version for "${name}".`);
        }
        const v = body?.versions?.[latest] ?? {};
        const maintainers = Array.isArray(body.maintainers)
            ? body.maintainers.map((m) => (typeof m === 'object' && m ? m.name || m.email || '' : String(m))).filter(Boolean).join(', ')
            : '';
        const keywords = Array.isArray(v.keywords) ? v.keywords.join(', ') : '';
        return [{
            name: String(body.name ?? name),
            latestVersion: String(latest),
            description: String(v.description ?? body.description ?? ''),
            license: typeof v.license === 'string' ? v.license : (v.license?.type ?? ''),
            homepage: String(v.homepage ?? ''),
            repository: repoUrl(v.repository),
            bugs: bugUrl(v.bugs),
            maintainers,
            keywords,
            created: String(body.time?.created ?? '').slice(0, 10),
            modified: String(body.time?.modified ?? '').slice(0, 10),

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Confirm the package is published with a latest release (`npm view <name> version` should return a version).
  2. If the package was unpublished, it cannot be queried until republished — use a different package or accept absence.
  3. Point NPM_REGISTRY at an up-to-date registry if behind a stale mirror/cache.
  4. Catch EmptyResultError and fall back to a direct registry fetch if you need raw packument data.

Example fix

// before
await npmPackage({ name: 'deleted-pkg' }); // EmptyResultError: no latest version
// after
try {
  return await npmPackage({ name: 'deleted-pkg' });
} catch (e) {
  if (e.name === 'EmptyResultError') return null; // likely unpublished; report absence
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

const res = await fetch(`https://registry.npmjs.org/${encodeURIComponent(name).replace('%2F', '/')}`);
const pack = await res.json();
if (!pack || !pack['dist-tags'] || !pack['dist-tags'].latest) {
  throw new Error(`${name} has no latest version (likely unpublished)`);
}

Type guard

function hasLatestVersion(pack) {
  return !!pack && typeof pack === 'object' &&
    !!pack['dist-tags'] && typeof pack['dist-tags'].latest === 'string' &&
    !!pack.versions && typeof pack.versions === 'object';
}

Try / catch

try {
  return await npmPackage({ name });
} catch (e) {
  if (e.name === 'EmptyResultError') return null; // likely unpublished; report absence
  throw e;
}

Prevention

When it happens

Trigger: Querying a name whose packument has no versions or no dist-tags.latest — e.g. an unpublished package (npm unpublish leaves a stub packument), a reserved name without content, a registry mirror with partial data, or a removed typosquat.

Common situations: Looking up a package that was unpublished; names removed for policy reasons; corporate proxies/caches serving degraded or empty packuments; deprecated packages whose dist-tags were stripped.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/37119f4a5933af85. Report an issue: GitHub.