{"record":{"id":"c8a8d5cc913b185f","repo":"trpc/trpc","slug":"no-fetch-implementation-found","errorCode":null,"errorMessage":"No fetch implementation found","messagePattern":"No fetch implementation found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/client/src/getFetch.ts","lineNumber":22,"sourceCode":"\nconst isFunction = (fn: unknown): fn is AnyFn => typeof fn === 'function';\n\nexport function getFetch(\n  customFetchImpl?: FetchEsque | NativeFetchEsque,\n): FetchEsque {\n  if (customFetchImpl) {\n    return customFetchImpl as FetchEsque;\n  }\n\n  if (typeof window !== 'undefined' && isFunction(window.fetch)) {\n    return window.fetch as FetchEsque;\n  }\n\n  if (typeof globalThis !== 'undefined' && isFunction(globalThis.fetch)) {\n    return globalThis.fetch as FetchEsque;\n  }\n\n  throw new Error('No fetch implementation found');\n}\n","sourceCodeStart":4,"sourceCodeEnd":24,"githubUrl":"https://github.com/trpc/trpc/blob/acff82332de8b4562d3e6975fa8d94ab1a6de5e0/packages/client/src/getFetch.ts#L4-L24","documentation":"The tRPC client needs a `fetch` implementation to perform HTTP requests. getFetch() checks, in order: an explicitly passed `customFetchImpl`, then `window.fetch`, then `globalThis.fetch`. If none of these is a function, the client cannot make HTTP calls and throws. This is a startup/runtime environment check, not a network error.","triggerScenarios":"Creating a client with httpLink/httpBatchLink/httpBatchStreamLink and issuing any query or mutation inside a runtime that exposes no global `fetch`. Also triggered when constructing the link eagerly resolves the fetcher before any request is sent in such an environment.","commonSituations":"Running tRPC client on Node.js < 18 (no built-in fetch), Jest/jsdom configs that don't polyfill fetch, old React Native engines, edge runtimes with fetch disabled, or SSR entry points that import the client before the runtime provides fetch.","solutions":["Upgrade to Node.js 18+ (or any runtime with a global fetch).","Pass an explicit fetch to the link via `fetch` option, e.g. `httpBatchLink({ url, fetch })` or `createTRPCClient({ links: [...], fetch })`.","Install `undici` / `cross-fetch` and set `globalThis.fetch = undici.fetch` before importing the client.","In tests, configure the test env to provide a fetch (jsdom + `whatwg-fetch`, or vitest's `environment: 'jsdom'` with fetch enabled)."],"exampleFix":"// before\nimport { createTRPCClient, httpBatchLink } from '@trpc/client';\nconst client = createTRPCClient({ links: [httpBatchLink({ url: '/api/trpc' })] });\n// throws on Node 16\n\n// after\nimport { fetch } from 'undici';\nconst client = createTRPCClient({\n  links: [httpBatchLink({ url: '/api/trpc', fetch })],\n});","handlingStrategy":"validation","validationCode":"// Run before creating the client\nfunction resolveFetch(explicit?: typeof fetch): typeof fetch | undefined {\n  if (explicit) return explicit;\n  const g = globalThis as { fetch?: typeof fetch; window?: { fetch?: typeof fetch } };\n  return g.fetch ?? g.window?.fetch;\n}\nconst fetchImpl = resolveFetch(myOpts.fetch);\nif (!fetchImpl) throw new Error('Configure a fetch polyfill for this runtime');","typeGuard":"const hasFetch = (): fetch is typeof fetch =>\n  typeof globalThis !== 'undefined' &&\n  typeof (globalThis as { fetch?: unknown }).fetch === 'function';","tryCatchPattern":"try {\n  const client = createTRPCClient({ links: [httpBatchLink({ url: '/api/trpc', fetch: fetchImpl })] });\n} catch (e) {\n  if (e instanceof Error && e.message === 'No fetch implementation found') {\n    // install polyfill and retry, or surface a clear env error\n  }\n  throw e;\n}","preventionTips":["Always pass `fetch` explicitly to link options in isomorphic code.","Pin Node >= 18 in package.json `engines` so a global fetch always exists.","In tests, assert fetch availability in a global setup file."],"tags":["fetch","runtime","environment","node","ssr"],"backgroundTag":null,"analyzedSha":"acff82332de8b4562d3e6975fa8d94ab1a6de5e0","analyzedAt":"2026-08-12T22:04:41.179Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}