Version of node.js...v14.15.4
PROBLEM
When I executed query in Apollo Server, I encountered this error message from the server.
"errors": [ { "message": "fetch is not defined", "locations": [ { "line": 3, "column": 1 }........
What does this mean? "fetch" is a method that handles request and response in asynchronous communication. Looks like this method is causing this error message.
const resolvers = { Query: { singlePokemon:async(parent, args) => { let res = await fetch(`https://pokeapi.co/api/v2/pokemon/${args.id}`);
SOLUTION
The version of Node before 18 does not have the fetch API. So, you need to install an external module.
https://www.npmjs.com/package/node-fetch
npm install node-fetch
Top comments (0)