How to disable ESLint to some folders in NextJS app directory?
When executing npm run build
in NextJS, eslint may check some folders that are unnecessary. If you are using App Router and want to disable ESLint to some folders, you can try the following ways.
Edit next.config.js
You can specify which directories should be checked by the ESLint. Here is the documentation: Linting Custom Directories and Files
module.exports = {
eslint: {
dirs: ['pages', 'utils'], // Only run ESLint on the 'pages' and 'utils' directories during production builds (next build)
},
}
If you want to exclude some folders that ESLint runs, you can try the following (note that ignoreDuringBuilds
only supports a boolean in the latest version of next):
module.exports = {
eslint: {
ignoreDuringBuilds: ['/src/core']
},
}
Or you can try the following if you want to completely disable ESLint, i.e. disable ESLint to all folders:
module.exports = {
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true,
},
}
Edit tsconfig.json
You can also edit tsconfig.json, this can not only disable ESLint to some folders in build phase, but also disable prettier to run on some folders.
{
"exclude": [
"node_modules",
"src/core/vite.config.ts"
]
}
There is no comment, let's add the first one.