{"record":{"id":"7637d1ba8cf76a74","repo":"vercel/turborepo","slug":"unable-to-fetch-the-latest-version-of-packagenam","errorCode":null,"errorMessage":"Unable to fetch the latest version of ${packageName}","messagePattern":"Unable to fetch the latest version of (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/turbo-codemod/src/commands/migrate/steps/get-latest-version.ts","lineNumber":24,"sourceCode":"  \"dist-tags\": {\n    latest: string;\n    [key: string]: string;\n  };\n  versions: Record<string, { name: string; version: string }>;\n}\n\nasync function getPackageDetails({ packageName }: { packageName: string }) {\n  const registry =\n    process.env.npm_config_registry?.replace(/\\/$/, \"\") || DEFAULT_REGISTRY;\n\n  try {\n    const response = await fetch(`${registry}/${packageName}`);\n    if (!response.ok) {\n      throw new Error(`HTTP ${response.status}`);\n    }\n    return (await response.json()) as PackageDetailsResponse;\n  } catch (err) {\n    throw new Error(`Unable to fetch the latest version of ${packageName}`);\n  }\n}\n\nexport async function getLatestVersion({\n  to\n}: MigrateCommandOptions): Promise<string | undefined> {\n  const packageDetails = await getPackageDetails({ packageName: \"turbo\" });\n  const { \"dist-tags\": tags, versions } = packageDetails;\n\n  if (to) {\n    // If 'to' is a dist-tag (e.g. \"latest\", \"canary\"), resolve to the concrete version\n    if (tags[to]) {\n      return tags[to];\n    }\n    if (to in versions) {\n      return to;\n    }\n    throw new Error(`turbo@${to} does not exist`);","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/vercel/turborepo/blob/f9245100cf0d31d96628804ead485f6bf226e55a/packages/turbo-codemod/src/commands/migrate/steps/get-latest-version.ts#L6-L42","documentation":"The turbo-codemod migrate command queries the npm registry for turbo metadata to learn the latest version. getPackageDetails fetches `${registry}/turbo`, where the registry comes from npm_config_registry or defaults to npmjs. It throws this Error when the request fails, returns a non-OK HTTP status, or the body cannot be parsed as JSON.","triggerScenarios":"No network access, DNS failure, or a corporate proxy blocks the registry. A custom npm_config_registry value points to an unreachable or private registry that does not serve the turbo package. The registry returns HTTP 404 or 5xx. response.json() fails because the response is not JSON.","commonSituations":"Running @turbo/codemod migrate behind a corporate proxy or firewall. A custom Artifactory or Verdaccio mirror that lacks the turbo package. A typo in npm_config_registry. Transient network outage or registry downtime.","solutions":["Verify connectivity: curl https://registry.npmjs.org/turbo or npm ping","Fix or unset npm_config_registry so it points to a registry that serves turbo metadata","Configure proxy settings (HTTPS_PROXY) or connect to a network that allows registry access","Retry the migrate command; registry requests are often transient failures"],"exampleFix":"# before: broken registry override\nnpm_config_registry=https://registry.internal.example npm exec @turbo/codemod migrate\n# after: default registry\nnpm exec @turbo/codemod migrate","handlingStrategy":"retry","validationCode":"// verify registry reachability for turbo metadata before running the codemod\nconst registry = (process.env.npm_config_registry ?? \"https://registry.npmjs.org\").replace(/\\/$/, \"\");\nconst res = await fetch(`${registry}/turbo`, { method: \"HEAD\" });\nif (!res.ok) {\n  throw new Error(`Registry not reachable for turbo: HTTP ${res.status}`);\n}","typeGuard":null,"tryCatchPattern":"async function fetchPackageDetailsWithRetry(url: string, attempts = 3) {\n  for (let i = 0; i < attempts; i++) {\n    try {\n      const res = await fetch(url);\n      if (res.ok) return await res.json();\n      if (res.status >= 500 && i < attempts - 1) continue; // retry server errors\n      throw new Error(`HTTP ${res.status}`);\n    } catch (err) {\n      if (i === attempts - 1) throw new Error(\"Unable to fetch the latest version of turbo\");\n      await new Promise((r) => setTimeout(r, 2 ** i * 500)); // backoff\n    }\n  }\n}","preventionTips":["Confirm npm ping and proxy settings before running @turbo/codemod migrate","Keep npm_config_registry pointed at a registry that mirrors the full turbo package","Cache or pin a known-good version to fall back on when the registry is down"],"tags":["turbo-codemod","network","npm-registry","migrate","version-resolution"],"backgroundTag":"npm-registry-request-failed","analyzedSha":"f9245100cf0d31d96628804ead485f6bf226e55a","analyzedAt":"2026-08-17T10:46:15.696Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}