{"record":{"id":"272496376d9e1732","repo":"twentyhq/twenty","slug":"global-fetch-function-is-not-available-pass-a-f","errorCode":null,"errorMessage":"Global `fetch` function is not available, pass a fetch polyfill to Genql `createClient`","messagePattern":"Global `fetch` function is not available, pass a fetch polyfill to Genql `createClient`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-client-sdk/src/generate/genql/runtime/fetcher.ts","lineNumber":38,"sourceCode":"\nexport const createFetcher = ({\n    url,\n    headers = {},\n    fetcher,\n    fetch: _fetch,\n    batch = false,\n    ...rest\n}: ClientOptions): Fetcher => {\n    if (!url && !fetcher) {\n        throw new Error('url or fetcher is required')\n    }\n    if (!fetcher) {\n        fetcher = async (body) => {\n            let headersObject =\n                typeof headers == 'function' ? await headers() : headers\n            headersObject = headersObject || {}\n            if (typeof fetch === 'undefined' && !_fetch) {\n                throw new Error(\n                    'Global `fetch` function is not available, pass a fetch polyfill to Genql `createClient`',\n                )\n            }\n            let fetchImpl = _fetch || fetch\n            const res = await fetchImpl(url!, {\n                headers: {\n                    'Content-Type': 'application/json',\n                    ...headersObject,\n                },\n                method: 'POST',\n                body: JSON.stringify(body),\n                ...rest,\n            })\n            if (!res.ok) {\n                throw new Error(`${res.statusText}: ${await res.text()}`)\n            }\n            const json = await res.json()\n            return json","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-client-sdk/src/generate/genql/runtime/fetcher.ts#L20-L56","documentation":"Generated gengl code: when no custom `fetcher` is provided, the SDK builds one on top of a `fetch` implementation. If the global `fetch` is undefined (the runtime has no native fetch and no polyfill was passed via the `fetch` option), it throws because it has no way to perform the POST. This is an environment/polyfill issue, not a network or URL issue.","triggerScenarios":"Running the SDK in an old Node version (<18, before global `fetch`), in a JS environment without a native fetch, in a bundler config that did not polyfill fetch, or in SSR/build contexts where `fetch` is not defined — and the caller did not pass a `fetch` polyfill to `createClient`.","commonSituations":"Upgrading/downgrading the Node runtime; running generated SDK code in a bare test harness; a bundler tree-shaking or aliasing `fetch`; executing during a build step where the fetch global is absent.","solutions":["Run on Node 18+ (which provides a global `fetch` via undici).","Pass an explicit fetch implementation to `createClient`, e.g. `createClient({ url, fetch: require('node-fetch') })` or pass `cross-fetch`/`undici`'s fetch.","If a bundler is stripping/aliasing fetch, configure it to keep the global or inject a polyfill.","Confirm the environment actually exposes `fetch` (a quick `typeof fetch` check) before constructing the client."],"exampleFix":"// before\nconst client = createClient({ url: endpoint, headers });\n// throws on Node <18: \"Global `fetch` function is not available...\"\n\n// after\nimport { fetch as undiciFetch } from 'undici';\nconst client = createClient({\n  url: endpoint,\n  headers,\n  fetch: typeof fetch === 'undefined' ? undiciFetch : fetch,\n});","handlingStrategy":"validation","validationCode":"if (typeof fetch === 'undefined' && !customFetch) {\n  throw new Error('No global fetch and no polyfill provided to createClient');\n}\nconst client = createClient({ url: endpoint, headers, fetch: customFetch });","typeGuard":"const hasFetchAvailable = (opts: Partial<ClientOptions>): boolean =>\n  typeof fetch === 'function' || typeof opts.fetch === 'function';","tryCatchPattern":null,"preventionTips":["Run the SDK on Node 18+ (native global fetch) or pass an explicit fetch polyfill.","Always pass the `fetch` option when targeting runtimes that may lack a global fetch.","Add a runtime check (`typeof fetch`) before constructing the client in shared libraries.","Pin the Node/bundler version so a fetch regression is caught in CI."],"tags":["client-sdk","genql","runtime","node","polyfill","fetch"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}