Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: fetch is not defined #15

Open
swiiny opened this issue Mar 2, 2023 · 0 comments
Open

Error: fetch is not defined #15

swiiny opened this issue Mar 2, 2023 · 0 comments

Comments

@swiiny
Copy link

swiiny commented Mar 2, 2023

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:

  1. Call getUsersDrawResultsForDrawId() (see this tutorial at step 6.3)
const drawResults = await prizeDistributor.getUsersDrawResultsForDrawId(
	usersAddress,
	draw.drawId,
	prizeDistribution.maxPicksPerUser
);
  1. 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

  1. Run npm i node-fetch
  2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant