Update

NextJS now has official guide to add eslint to project: https://nextjs.org/docs/basic-features/eslint Additionally you need to install ESLint extension.

Also, If you're looking for ESLint with typescript support: https://gourav.io/blog/nextjs-cheatsheet

Old answer:

Install ESLint

npm i eslint --save-dev

Install ESLint plugins:

npx install-peerdeps --dev eslint-config-airbnb

Above single command will install 6 plugins: eslint-config-airbnb, eslint-plugin-import, eslint-plugin-react, eslint-plugin-react-hooks, and eslint-plugin-jsx-a11y. You can also install these plugins individually.

Install babel eslint

npm i -D babel-eslint

Install prettier plugin (optional, so that prettier doesn't mess up with linting)

 npm i -D eslint-config-prettier eslint-plugin-prettier

Your "devDependencies" should look something like this:

"devDependencies": {
    "babel-eslint": "^10.1.0",
    "eslint": "^6.8.0",
    "eslint-config-airbnb": "^18.1.0",
    "eslint-config-prettier": "^6.11.0",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-prettier": "^3.1.3",
    "eslint-plugin-react": "^7.20.0",
    "eslint-plugin-react-hooks": "^2.5.1"
  }

Now, create a file .eslintrc.json at root of project. Paste below config:

{
  "env": {
    "browser": true,
    "commonjs": true,
    "es6": true,
    "node": true
  },
  "parser": "babel-eslint",
  "extends": [
    "eslint:recommended",
    "airbnb",
    "airbnb/hooks",
    "plugin:react/recommended",
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:jsx-a11y/recommended",
    // "plugin:react-hooks/recommended",
    // always put prettier at last
    "prettier"
  ],
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
  },
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true // enable linting for jsx files
    },
    "ecmaVersion": 11,
    "sourceType": "module"
  },
  "settings": {
    "react": {
      "version": "detect"
    }
  },
  "plugins": ["react", "react-hooks"],
  "rules": {
    // NextJs specific fix: suppress errors for missing 'import React' in files for nextjs
    "react/react-in-jsx-scope": "off",
   // NextJs specific fix: allow jsx syntax in js files
    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], //should add ".ts" if typescript project
    "react/display-name": 1
  }
}

Also, install ESLint extension for VSCode.

Reload VSCode window once to get proper linting

ESLint will automatically start detecting errors/warnings in *.js and *.jsx files. If that's not the case then either your project has no linting errors or ESLint is not properly setup. To test if linting works run eslint command in terminal with folder path i.e. eslint pages/** and notice output.

To disable linting of some files/folders you can create a .eslintignore at the root of project.

.eslintignore:

# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
dist
# don't lint nyc coverage output
coverage

Finally, you can also add linting to scripts in package.json as a part of your build/deploy process:

"scripts": {
    "lint": "eslint ./components/** ./pages/** -c .eslintrc.json --ext js,jsx",
    "lint-fix": "eslint ./components/** ./pages/** -c .eslintrc.json --fix --ext js,jsx",
}

See my current ESLint configuration for NextJS Typescript project: https://github.com/GorvGoyl/Personal-Site-Gourav.io/blob/main/.eslintrc.js

Answer from GorvGoyl on Stack Overflow
Top answer
1 of 3
37

Update

NextJS now has official guide to add eslint to project: https://nextjs.org/docs/basic-features/eslint Additionally you need to install ESLint extension.

Also, If you're looking for ESLint with typescript support: https://gourav.io/blog/nextjs-cheatsheet

Old answer:

Install ESLint

npm i eslint --save-dev

Install ESLint plugins:

npx install-peerdeps --dev eslint-config-airbnb

Above single command will install 6 plugins: eslint-config-airbnb, eslint-plugin-import, eslint-plugin-react, eslint-plugin-react-hooks, and eslint-plugin-jsx-a11y. You can also install these plugins individually.

Install babel eslint

npm i -D babel-eslint

Install prettier plugin (optional, so that prettier doesn't mess up with linting)

 npm i -D eslint-config-prettier eslint-plugin-prettier

Your "devDependencies" should look something like this:

"devDependencies": {
    "babel-eslint": "^10.1.0",
    "eslint": "^6.8.0",
    "eslint-config-airbnb": "^18.1.0",
    "eslint-config-prettier": "^6.11.0",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-prettier": "^3.1.3",
    "eslint-plugin-react": "^7.20.0",
    "eslint-plugin-react-hooks": "^2.5.1"
  }

Now, create a file .eslintrc.json at root of project. Paste below config:

{
  "env": {
    "browser": true,
    "commonjs": true,
    "es6": true,
    "node": true
  },
  "parser": "babel-eslint",
  "extends": [
    "eslint:recommended",
    "airbnb",
    "airbnb/hooks",
    "plugin:react/recommended",
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:jsx-a11y/recommended",
    // "plugin:react-hooks/recommended",
    // always put prettier at last
    "prettier"
  ],
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
  },
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true // enable linting for jsx files
    },
    "ecmaVersion": 11,
    "sourceType": "module"
  },
  "settings": {
    "react": {
      "version": "detect"
    }
  },
  "plugins": ["react", "react-hooks"],
  "rules": {
    // NextJs specific fix: suppress errors for missing 'import React' in files for nextjs
    "react/react-in-jsx-scope": "off",
   // NextJs specific fix: allow jsx syntax in js files
    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], //should add ".ts" if typescript project
    "react/display-name": 1
  }
}

Also, install ESLint extension for VSCode.

Reload VSCode window once to get proper linting

ESLint will automatically start detecting errors/warnings in *.js and *.jsx files. If that's not the case then either your project has no linting errors or ESLint is not properly setup. To test if linting works run eslint command in terminal with folder path i.e. eslint pages/** and notice output.

To disable linting of some files/folders you can create a .eslintignore at the root of project.

.eslintignore:

# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
dist
# don't lint nyc coverage output
coverage

Finally, you can also add linting to scripts in package.json as a part of your build/deploy process:

"scripts": {
    "lint": "eslint ./components/** ./pages/** -c .eslintrc.json --ext js,jsx",
    "lint-fix": "eslint ./components/** ./pages/** -c .eslintrc.json --fix --ext js,jsx",
}

See my current ESLint configuration for NextJS Typescript project: https://github.com/GorvGoyl/Personal-Site-Gourav.io/blob/main/.eslintrc.js

2 of 3
15

you need to install required npm modules.

with Npm:

npm i -D babel-eslint eslint-config-airbnb eslint eslint-plugin-jsx-a11y eslint-plugin-import eslint-plugin-react eslint-plugin-react-hooks

with Yarn:

yarn add -D babel-eslint eslint-config-airbnb eslint eslint-plugin-jsx-a11y eslint-plugin-import eslint-plugin-react eslint-plugin-react-hooks

Here is related article about that

https://medium.com/@melih193/next-js-eslint-setup-tutorial-for-airbnb-config-c2b04183a92a

🌐
Danielfullstack
danielfullstack.com › article › how-to-configure-eslint-with-nextjs-in-3-minutes
How to Configure ESlint with Nextjs in 3 Minutes
Create a file called .eslintrc.json in the root of your Nextjs project and copy the following settings. NOTE: I have added comments for each line to give a basic explanation of what each rule does.
Discussions

What ESLint Plugins Do You Recommend When Using NextJs?
Here is my ESLint plugins I use for all my NextJS projects: https://github.com/ixartz/Next-js-Boilerplate/blob/main/package.json#L85-L102 There are 18 plugins. I also use ESLint plugins for testing part: Jest, Playwright, Storybook, etc. And here you can find how I configure everything: https://github.com/ixartz/Next-js-Boilerplate/blob/main/.eslintrc More on reddit.com
🌐 r/reactjs
25
14
February 20, 2024
What ESLint rules do you enable that are not enabled by default?
I am constantly shocked that this rule isn't just a part of ESLint. Every single time I enter a new codebase, I cry a little inside. I use almost every rule in this plugin, but I find this the most important https://mysticatea.github.io/eslint-plugin-eslint-comments/rules/require-description.html More on reddit.com
🌐 r/nextjs
20
31
July 4, 2024
Shared ESLint & Prettier config package for Next.js v14
Why you choose to use eslint 8? AFAIK it is not supported anymore by eslint team. More on reddit.com
🌐 r/nextjs
13
6
January 12, 2025
add eslint + prettier to a fresh new nextjs app
It comes with ES Lint support out of the box. You can configure it based on your needs, extending or adding more es lint rules. For prettier just create a prettier.config.js file and add your desired settings. https://nextjs.org/docs/basic-features/eslint#eslint-plugin More on reddit.com
🌐 r/nextjs
1
3
November 22, 2022
🌐
Devinshoemaker
devinshoemaker.com › blog › next-js › configure-eslint
Configure ESLint for Next.js
eslint-plugin-react is a plugin for ESLint with rules specific to React.
🌐
npm
npmjs.com › package › eslint-config-next
eslint-config-next - npm
January 27, 2026 - ESLint configuration used by Next.js.. Latest version: 16.1.6, last published: a month ago. Start using eslint-config-next in your project by running `npm i eslint-config-next`. There are 1677 other projects in the npm registry using eslint-config-next.
      » npm install eslint-config-next
    
Published   Jan 27, 2026
Version   16.1.6
🌐
DEV Community
dev.to › celest67 › nextjs-with-eslint-3gl5
Next.js with ESLint - DEV Community
February 8, 2023 - ESLint also contains code formatting rules, which can conflict with your existing Prettier setup.
🌐
GeeksforGeeks
geeksforgeeks.org › next-js-eslint
Next.js ESLint - GeeksforGeeks
July 25, 2024 - For a Next.js project, we can use ... in. For a Next.js project, we can use a browser and node. rules: This option specifies which rules to enable or disable....
Find elsewhere
🌐
Medium
medium.com › @ray.an › extend-nextjs-eslint-with-typescript-and-prettier-support-24ef03a29315
Setup Nextjs Eslint with Typescript and Prettier | by Ray A | Medium
April 29, 2024 - In this article, we will specifically use a Nextjs app to configure around. Create and name the app as my-app with typescript and eslint preconfigured. ... Just go on with defaults for the other configuration prompts in your terminal. ... Once finished, you may check the linter as it works. ... @typescript-eslint/eslint-plugin provides Eslint rules ...
🌐
Medium
medium.com › @anoopnayak1 › boost-next-js-development-with-eslint-an-essential-guide-to-production-level-setup-a9e5890d2b6f
Boost Next.js Development with ESLint: An Essential Guide to Production-Level Setup | by Anoop Nayak | Medium
July 26, 2023 - Allows specific rule exceptions for files under “src/iconify-bundle/” to use require statements. Step 4: Make changes to your package.json file · "scripts": { "lint": "next lint" } Thats it! When ever you are done with any changes, run · npm run lint · Embrace the sweet pain of code improvement with ESLint · Where coding and comedy collide! Embrace the linting fun, and let your code shine like a stand-up star! Eslint · Eslint Config · Nextjs ·
🌐
Medium
medium.com › @wahvanessa22 › im-setting-up-eslint-for-my-next-js-a6f22ebf768b
I'm setting up ESLint for my Next.js + TypeScript project to keep my code clean, consistent, and bug-free. A step you should consider when writing like a pro! | by Wah Vanessa | Medium
May 13, 2025 - Being the core concept in ESLint, rules agree on what you have done that is valid and also let you know what needs to be done, providing suggestions without changing the application's logic, known as Rule fixes.
🌐
DEV Community
dev.to › jordanahaines › just-use-this-nextjs-eslint-configuration-540
Just use this Next.js Eslint Configuration - DEV Community
January 12, 2025 - My config to enforce code style in a project with Next.JS, Tailwind, Drizzle, and - obviously - Typescript. Tagged with nextjs, eslint, typescript, tailwindcss.
🌐
Next.js
nextjs.org › docs › 14 › app › building-your-application › configuring › eslint
Configuring: ESLint | Next.js
August 22, 2024 - To improve performance, information of files processed by ESLint are cached by default. This is stored in .next/cache or in your defined build directory. If you include any ESLint rules that depend on more than the contents of a single source file and need to disable the cache, use the --no-cache flag with next lint.
🌐
GitHub
github.com › vercel › next.js › discussions › 50453
How can I use the new ESLint flat config in a Next.js project and also use 'canonical' rules? · vercel/next.js · Discussion #50453
// mimic CommonJS variables -- not needed if using CommonJS const filename = fileURLToPath(import.meta.url); const dirname = path.dirname(filename); const compat = new FlatCompat({ baseDirectory: dirname, }); const customRules = { '@babel/object-curly-spacing': 'off', 'array-bracket-newline': 'off', 'array-element-newline': 'off', 'func-style': 'off', 'line-comment-position': 'off', // https://eslint.org/docs/latest/rules/max-len 'max-len': ['warn', { code: 150, ignoreComments: false, ignoreRegExpLiterals: true, ignoreStrings: true, ignoreTemplateLiterals: true }], // https://eslint.org/docs/r
Author   vercel
🌐
ESLint
eslint.org › docs › latest › use › getting-started
Getting Started with ESLint
Alternatively, you can use configurations that others have created by searching for “eslint-config” on npmjs.com. ESLint will not lint your code unless you extend from a shared configuration or explicitly turn rules on in your configuration.
🌐
Next.js
nextjs.org › docs › app › api-reference › config › eslint
Configuration: ESLint | Next.js
2 weeks ago - import nextConfig from 'eslint-config-next/core-web-vitals' // Your other config imports... const eslintConfig = [ // Your other configurations... ...nextConfig, ] export default eslintConfig · When you spread ...nextConfig, you're adding multiple config objects that include file patterns, plugins, rules, ignores, and parser settings.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-set-up-eslint-prettier-stylelint-and-lint-staged-in-nextjs
How to Set Up ESLint, Prettier, StyleLint, and lint-staged in Next.js
May 30, 2025 - An ESLint plugin defines some linting rules. For example, if you look in the GitHub repo for Next's ESLint plugin, eslint-plugin-next, each file in the src/rules folder defines a linting rule as a TypeScript function.
🌐
Next.js
nextjs.org › docs › pages › building-your-application › configuring › eslint
ESLint
2 weeks ago - import nextConfig from 'eslint-config-next/core-web-vitals' // Your other config imports... const eslintConfig = [ // Your other configurations... ...nextConfig, ] export default eslintConfig · When you spread ...nextConfig, you're adding multiple config objects that include file patterns, plugins, rules, ignores, and parser settings.
🌐
LogRocket
blog.logrocket.com › home › troubleshooting a next.js app with eslint
Troubleshooting a Next.js app with ESLint - LogRocket Blog
June 4, 2024 - I also have some general rules for clean code, like no else return statements, using const where possible, no unneeded ternary, and giving warnings if there are console logs present, because usually in production there typically shouldn’t be any console logs. These make sure that code is consistent throughout the codebase. You can add or reduce this config as your preference dictates! ESLint is extremely useful and using it in Next.js will help you and your teammates ready your code easily and troubleshoot bugs easily 🚀. It will take some time to get used to it but it will definitely help you in the long run!