ESLint Configuration Error Fix
In this tutorial, you'll learn about ESLint Configuration Error Fix. We cover key concepts, practical examples, and best practices.
The Problem
You run eslint . and get Error: Failed to load plugin or ESLint configuration is invalid. ESLint configuration errors occur when plugins are missing, config syntax is wrong, or extends chains conflict.
Quick Fix
Step 1: Install missing plugins and parsers
npm install -D eslint-plugin-react @typescript-eslint/parser @typescript-eslint/eslint-plugin
Expected output: The missing plugins and parsers are installed.
Step 2: Validate config file syntax
eslint --print-config .eslintrc.js
Expected output on success:
{
"env": { ... },
"rules": { ... },
}
If this fails, the error message points to the exact line causing the problem.
Step 3: Use .eslintrc.js instead of JSON
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'eslint:recommended',
'plugin:"@typescript"-eslint/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
rules: {
'no-unused-vars': 'warn',
'@typescript-eslint/no-explicit-any': 'error',
},
};
Expected output: JS format supports comments, trailing commas, and conditional config.
Step 4: Resolve extends chain conflicts
eslint --ext .js,.ts --debug .
Expected output: The --debug flag shows which config files are loaded and their resolution order.
Step 5: Fix parserOptions.project for TypeScript
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
}
Remove parserOptions.project if you do not need type-aware linting:
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
}
Expected output: ESLint works without requiring tsconfig for non-type-aware rules.
Step 6: Use flat config for ESLint 9+
// eslint.config.js
import js from '@eslint/js';
export default [
js.configs.recommended,
{
files: ['**/*.js'],
rules: {
'no-unused-vars': 'warn',
},
},
];
Expected output: Flat config replaces .eslintrc.* and eliminates extends chain confusion.
Prevention
- Use
.eslintrc.jsinstead of JSON for comments and conditional configs - Always run
eslint --print-configafter editing config - Install all
extendsandpluginsas dev dependencies - Use either
.eslintrc.*or flat config (eslint.config.js), never both
Common Mistakes with config error
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists - Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad
These mistakes appear frequently in real-world ESLINT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro