elVengador
elVengador

Reputation: 630

How to disable eslint to some folders in nextjs?

I want to disable eslint to some folders when execute npm run build in NextJs

I dont want to configure like this:

module.exports = {
  eslint: {
    dirs: ['pages', 'utils'], // Only run ESLint on the 'pages' and 'utils' directories during production builds (next build)
  },
}

because is complicate to add all my valid folders, but is more easy if I could pass some folders to be ignored

Upvotes: 5

Views: 12793

Answers (4)

elVengador
elVengador

Reputation: 630

To disable eslint in some folders in NextJs, you need to edit next.config.js, here is the documentation: https://nextjs.org/docs/basic-features/eslint#linting-custom-directories-and-files

module.exports = {
  eslint: {
   ignoreDuringBuilds: ['/src/core']
  },
}

If you want to ignore some folder or files in build phase you need to edit tsconfig.json

{
  "exclude": [
    "node_modules",
    "src/core/vite.config.ts"
  ]
}

Upvotes: 2

Anthony
Anthony

Reputation: 29

You can create an .eslintignore file at the root of your project

https://eslint.org/docs/latest/user-guide/configuring/ignoring-code

Upvotes: 2

I'm Joe Too
I'm Joe Too

Reputation: 5870

If you want to ignore specific files or directories, add them to ignorePatterns in your eslint config:

module.exports = {
  ...,
  ignorePatterns: [
    "jest.config.js",
    "lib",
    "src/some-file.ts",
  ],
  ...
}

If you want it to only happen during the build phase, set up a second config file with the ignorePatterns and use the appropriate config for what you're doing (dev, build, whatever) with the -c or --config CLI option.

Upvotes: 6

cho_biz
cho_biz

Reputation: 69

Ignoring ESLint When ESLint is detected in your project, Next.js fails your production build (next build) when errors are present.

If you'd like Next.js to produce production code even when your application has ESLint errors, you can disable the built-in linting step completely. This is not recommended unless you already have ESLint configured to run in a separate part of your workflow (for example, in CI or a pre-commit hook).

Open next.config.js and enable the ignoreDuringBuilds option in the eslint config:

module.exports = {
  eslint: {
    // Warning: This allows production builds to successfully complete even if
    // your project has ESLint errors.
    ignoreDuringBuilds: true,
  },
}

Upvotes: 1

Related Questions