{"record":{"id":"f29bb1bc6afd9d19","repo":"twentyhq/twenty","slug":"global-fetch-function-is-not-available-pass-a-f-f29bb1","errorCode":null,"errorMessage":"Global `fetch` function is not available, pass a fetch implementation to the Twenty client","messagePattern":"Global `fetch` function is not available, pass a fetch implementation to the Twenty client","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/twenty-client-sdk/src/generate/twenty-client-template.ts","lineNumber":304,"sourceCode":"      }\n    }\n\n    return this.assertResponseIsSuccessful(firstResponse);\n  }\n\n  private async executeGraphqlRequest({\n    operation,\n    headers,\n    requestInit,\n    token,\n  }: {\n    operation: GraphqlOperation | GraphqlOperation[] | FormData;\n    headers?: HeadersInit;\n    requestInit?: RequestInit;\n    token: string | null;\n  }): Promise<GraphqlResponse> {\n    if (!this.fetchImplementation) {\n      throw new Error(\n        'Global `fetch` function is not available, ' +\n          'pass a fetch implementation to the Twenty client',\n      );\n    }\n\n    const resolvedHeaders = await this.resolveHeaders();\n    const requestHeaders = new Headers(resolvedHeaders);\n\n    if (headers) {\n      new Headers(headers).forEach((value, key) =>\n        requestHeaders.set(key, value),\n      );\n    }\n\n    if (operation instanceof FormData) {\n      requestHeaders.delete('Content-Type');\n    } else {\n      requestHeaders.set('Content-Type', 'application/json');","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-client-sdk/src/generate/twenty-client-template.ts#L286-L322","documentation":"Thrown by TwentyClient.executeGraphqlRequest (twenty-client-template.ts:303-308) when this.fetchImplementation is falsy at request time. The client only stores a fetch implementation if one was passed explicitly or `globalThis.fetch` existed when the client was constructed — otherwise it is null and every GraphQL call aborts.","triggerScenarios":"Constructing TwentyClient in an environment without a global fetch (Node.js < 18, older runtimes, some sandboxed contexts) and not passing a `fetch` option. The first GraphQL call then hits the guard.","commonSituations":"Running the SDK on Node 16 or 17 (fetch landed as unflagged global in Node 18); using jsdom or a test environment with fetch not polyfilled; SSR/build-time invocations in tooling that strips fetch; bundlers that tree-shake the global.","solutions":["Upgrade to Node.js 18+ where globalThis.fetch is built in.","Pass an explicit fetch implementation: `new TwentyClient({ fetch: crossFetch, ... })` (or undici, node-fetch, whatwg-fetch).","In tests, set globalThis.fetch = require('node-fetch') or jest.polyfill fetch before constructing the client.","Confirm the polyfill is imported before TwentyClient instantiation."],"exampleFix":"// before\nconst client = new TwentyClient({ apiUrl, accessToken });\n// after\nimport fetch from 'node-fetch';\nconst client = new TwentyClient({ apiUrl, accessToken, fetch });","handlingStrategy":"validation","validationCode":"const fetchImpl =\n  typeof globalThis.fetch === 'function'\n    ? globalThis.fetch\n    : (await import('node-fetch')).default;\nconst client = new TwentyClient({ apiUrl, accessToken, fetch: fetchImpl });","typeGuard":"const hasGlobalFetch = (): boolean => typeof globalThis.fetch === 'function';","tryCatchPattern":"try {\n  await client.someQuery();\n} catch (err) {\n  if (err.message.includes('Global `fetch` function is not available')) {\n    // pass a fetch polyfill to TwentyClient\n  }\n  throw err;\n}","preventionTips":["Pass an explicit `fetch` option when targeting Node < 18 or non-browser runtimes.","Polyfill globalThis.fetch before constructing the client in tests.","Pin Node version to 18+ in deployment configs.","Import the fetch polyfill at the top of the entry module."],"tags":["runtime","node","fetch","client-sdk","configuration"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}