How to disable or skip eslint during build process in nextjs or react
To disable ESLint in a Next.js project, you have a few options depending on your needs. Here's a step-by-step guide to doing it:
1. Disable ESLint for a Specific File
If you want to disable ESLint for a specific file, you can add the following comment at the top of the file:
/* eslint-disable */
2. Disable ESLint for Specific Lines
If you want to disable ESLint for specific lines, you can use the following comment:
// eslint-disable-next-line
console.log('This line will not be checked by ESLint');
3. Disable ESLint for Specific Rules
You can disable specific ESLint rules for a line or block:
// eslint-disable-next-line no-console
console.log('This line will not be checked for no-console rule');
const myFunction = () => {
/* eslint-disable no-alert */
alert('This block will not be checked for no-alert rule');
/* eslint-enable no-alert */
}
4. Disable ESLint in next.config.js
To disable ESLint checks during builds in a Next.js project, you can modify the next.config.js
file:
// next.config.js
module.exports = {
eslint: {
ignoreDuringBuilds: true,
},
}
5. Disable ESLint in the package.json
You can also disable ESLint by modifying the scripts in your package.json
:
{
"scripts": {
"lint": "echo 'Skipping lint' && exit 0",
"lint:fix": "echo 'Skipping lint:fix' && exit 0"
}
}
6. Uninstall ESLint
If you don't want ESLint in your project at all, you can uninstall it and remove its configuration files:
npm uninstall eslint
# or
yarn remove eslint
Then, remove any ESLint configuration files, like .eslintrc.js
, .eslintignore
, etc.
Example of next.config.js
with eslint
disabled during builds:
// next.config.js
module.exports = {
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true,
},
};
Published on: Jul 16, 2024, 10:07 AM