ReferenceError: fetch is not defined

Trying to connect to a Fuel local node via the TypeScript SDK, and running into this error: ReferenceError: fetch is not defined.

import { FUEL_NETWORK_URL, Provider } from "fuels"
const localProvider = await Provider.create(FUEL_NETWORK_URL)
// This fails as well too 
// const provider = await Provider.create("https://beta-5.fuel.network/graphql")

I’m running an in-memory node too, but I doubt that’s the issue.

Here’s the stacktrace:

ReferenceError: fetch is not defined
      at /Users/sluzhba/Documents/Dev/Burra Labs/ruscet-contracts/node_modules/@fuel-ts/providers/src/provider.ts:310:7
      at fetch (node_modules/@fuel-ts/providers/src/provider.ts:438:9)
      at /Users/sluzhba/Documents/Dev/Burra Labs/ruscet-contracts/node_modules/graphql-request/src/index.ts:177:16
      at step (node_modules/graphql-request/dist/index.js:63:23)
      at Object.next (node_modules/graphql-request/dist/index.js:44:53)
      at /Users/sluzhba/Documents/Dev/Burra Labs/ruscet-contracts/node_modules/graphql-request/dist/index.js:38:71
      at new Promise (<anonymous>)
      at __awaiter (node_modules/graphql-request/dist/index.js:34:12)
      at post (node_modules/graphql-request/dist/index.js:160:12)
      at /Users/sluzhba/Documents/Dev/Burra Labs/ruscet-contracts/node_modules/graphql-request/src/index.ts:466:26

It appears that the source of the error is here (but I could be wrong).

I’m using the current v0.73.0 of the SDK.

Hi, which version of nodejs are you using? We’re officially supporting the LTS versions v18 and v20. Native fetch has been added in nodejs v18. If you’re using an older version you’ll get the error you reported: ReferenceError: fetch is not defined.

2 Likes

ahhh, thank you so much. I was on version 16 of nodejs. This helped!

2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.