Describe the feature you'd like to request
These are common issues developers run into with Next.js. Some are mentioned in the docs, but ideally you don't have to go check the docs.
Describe the solution you'd like
Instead, ESLint can provide compile-time feedback and suggestions.
-
Trying to call an API route from inside getStaticProps / getServerSideProps leading to next build failing.
-
Trying to use getStaticProps inside of _app.js, assuming it works like the other pages, but it doesn't.
-
Forgetting to await an async function inside an API route, works fine locally but does out of band work which will cause issues if there’s multiple requests.
-
Code Example
// Found on stackoverflow
export default function handler(req, res) {
const { method } = req;
switch (method) {
case 'GET':
// but this is making a fetch and has no await....
getRestaurants();
break;
default:
res.status(405).end(`Method ${req.method} Not Allowed`);
}
function getRestaurants() {
const restaurants = data;
res.status(200).json(restaurants);
}
}
-
Using document or other browser APIs outside of useEffect
-
File name casing (e.g. myFile.js vs MyFile.js). This could potentially be solved with linting if import statement diffs from the actual file path? Not sure.
Describe alternatives you've considered
N/A
Describe the feature you'd like to request
These are common issues developers run into with Next.js. Some are mentioned in the docs, but ideally you don't have to go check the docs.
Describe the solution you'd like
Instead, ESLint can provide compile-time feedback and suggestions.
Trying to call an API route from inside
getStaticProps/getServerSidePropsleading to next build failing.Trying to use
getStaticPropsinside of_app.js, assuming it works like the other pages, but it doesn't.Forgetting to await an async function inside an API route, works fine locally but does out of band work which will cause issues if there’s multiple requests.
Code Example
Using
documentor other browser APIs outside ofuseEffectFile name casing (e.g.
myFile.jsvsMyFile.js). This could potentially be solved with linting if import statement diffs from the actual file path? Not sure.Describe alternatives you've considered
N/A