Menu

Showing posts with label fetch is not defined. Show all posts
Showing posts with label fetch is not defined. Show all posts

ReferenceError: fetch is not defined

If you are seeing this error while using the node that means your node version doesnt support out of the box fetch API. There could be two possible solution

1. Upgrade the node version

Check installed node version using command >> node -version

Then using this command update node version to latest node version. npm install -g node

2. Install node-fetch

You could use the fetch with your existing project and node version as well. For that you have to install the node-fetch and use it.


a). Node install command
npm install node-fetch@2

b). After successful install create a fetch constant in your JS file where you are usign the fetch. Like below.

const fetch = require("node-fetch");