I’m learning nextJS 15 and I’m making an app using the pokeAPI but when I run npm run build
eslint gives me the following message:
Error: ‘error’ is defined but never used. @typescript-eslint/no-unused-vars
The following code is the one producing the error:
const getPokemon = async (id: string) => {
try {
const pokemon = await fetch(`https://pokeapi.co/api/v2/pokemon/${id}`, {
cache: "force-cache"
}).then(res => res.json());
return pokemon;
} catch (error) {
notFound();
}
};
Is there a way to ignore that unused variable specifically?
Here’s the .eslintrc.json:
{
"extends": ["next/core-web-vitals", "next/typescript"]
}
I tried the no-unused-vars rule but it didn’t work
2
Answers
There are two ways you can go about fixing this
/* eslint-disable @typescript-eslint/no-unused-vars */
eslintrc.json
fileeslintrc.json
You can simply write the try catch without binding the error to a variable: