Skip to content

Common Next.js issues that could use integrated ESLint rules #27051

@leerob

Description

@leerob

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

Metadata

Metadata

Labels

LintingRelated to `next lint` or ESLint with Next.js.good first issueEasy to fix issues, good for newcomers

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions