vercel/next.js · error · Error

Failed to get registry from "${pkgManager}".

Error message

Failed to get registry from "${pkgManager}".

What it means

Thrown by getRegistry() when execSync(`<pkgManager> config get registry ...`) fails. The function needs the registry URL to download SWC binaries; if the package-manager subprocess errors (binary missing, command rejected, NODE_OPTIONS rejected), it re-throws wrapping the original error as `cause`.

Source

Thrown at packages/next/src/lib/helpers/get-registry.ts:37

  try {
    const output = execSync(
      `${pkgManager} config get registry ${resolvedFlags}`,
      {
        env: {
          ...process.env,
          NODE_OPTIONS: getFormattedNodeOptionsWithoutInspect(),
        },
      }
    )
      .toString()
      .trim()

    if (output.startsWith('http')) {
      registry = output.endsWith('/') ? output : `${output}/`
    }
  } catch (err) {
    throw new Error(`Failed to get registry from "${pkgManager}".`, {
      cause: err,
    })
  }

  return registry
}

View on GitHub (pinned to 0ae8c72462)

Solutions

  1. Ensure the detected package manager binary is installed and on PATH: `which npm` (or yarn/pnpm).
  2. Inspect err.cause from the thrown error for the real subprocess exit message and fix accordingly.
  3. Sanitize NODE_OPTIONS (remove --inspect and other disallowed flags) before running the build.
  4. Set the registry explicitly via NEXT_SWC_PATH or a pre-installed binary to bypass getRegistry entirely.

Example fix

# before: npm missing in container
pnpm build  # Failed to get registry from "npm"
# after: install npm or use pnpm consistently
apt-get install -y npm
# or avoid the path: pre-install the swc binary
pnpm add @next/swc-linux-x64-gnu
Defensive patterns

Strategy: validation

Validate before calling

import { execSync } from 'child_process'
function assertRegistryResolvable(pm: string) {
  try {
    execSync(`${pm} config get registry`, { stdio: 'pipe' })
  } catch (e) {
    throw new Error(`Package manager '${pm}' unavailable or misconfigured`, { cause: e })
  }
}

Type guard

function pkgManagerOnPath(pm: string): boolean {
  try { execSync(`${pm} --version`, { stdio: 'pipe' }); return true }
  catch { return false }
}

Try / catch

try {
  return getRegistry()
} catch (e) {
  if (/Failed to get registry/.test(e.message)) {
    console.error('Registry lookup failed — check package manager install and NODE_OPTIONS')
  }
  // fall back to default registry or pre-installed binary
  return 'https://registry.npmjs.org/'
}

Prevention

When it happens

Trigger: getRegistry() is called during SWC binary download. It runs `npm config get registry --no-workspaces` (or yarn/pnpm equivalent). If the pkg manager binary isn't on PATH, the command exits non-zero, or NODE_OPTIONS contains a disallowed flag that Node rejects, execSync throws and getRegistry re-wraps it.

Common situations: Container/CI images without npm/yarn/pnpm installed; a corrupted .npmrc that breaks `npm config`; NODE_OPTIONS containing --inspect which getFormattedNodeOptionsWithoutInspect strips but a leftover invalid token still breaks the child; or a custom package manager shim that exits non-zero. Often co-occurs with [107]/[108] since registry resolution precedes the download.

Related errors


AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06). Data as JSON: /api/errors/eea071dd9dd250ae. Report an issue: GitHub.