-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
Describe the bug
When running the client in a Node.js environment, the fetch is not defined error occurs while trying to get draw results.
To Reproduce
Steps to reproduce the behavior:
- Call
getUsersDrawResultsForDrawId()(see this tutorial at step 6.3)
const drawResults = await prizeDistributor.getUsersDrawResultsForDrawId(
usersAddress,
draw.drawId,
prizeDistribution.maxPicksPerUser
);- See error in terminal
my-project-name/node_modules/@pooltogether/v4-client-js/dist/v4-client-js.cjs.development.js:2072
return fetch(this.getDrawResultsStatusUrl(chainId, prizeDistributorAddress, drawId));
^
ReferenceError: fetch is not defined
Expected behavior
The expected behavior was to get draw results of a user
How I quickly fix this to make it works
- Run
npm i node-fetch - Add these lines at the beginning of my entry index.js file
import fetch from 'node-fetch';
globalThis.fetch = fetch;Desktop
- OS: macOS Monterey (12.3.1)
- Node: 16.16.0
- NPM: 8.11.0
Additional context
I believe this error is occurring because the client is being run in a Node.js environment instead of a browser. However, this issue may be resolved with the new Node.js v18 version, as they have introduced a fetch API. It is also worth noting that the package.json file indicates that the client should work on Node.js versions equal to or greater than 16.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels