ESLint indent rule reports tabs versus spaces on every line
Expected indentation of 1 tab but found 4 spaces indentShort answer
The indent rule is set to one style and your files use another. Decide which style the project wants, set the rule to match, then run eslint --fix to rewrite the files. The editor can also fight back: VS Code detects indentation per file and overrides your defaults.
Fix it fast
1Find out which cause you have
Find the indent setting ESLint actually uses, so you know whether the rule wants tabs or a number of spaces.
grep -rn "indent" eslint.config.* .eslintrc* 2>/dev/null2Match what you see, then jump to its fix
- 1
Every indented line fails, not just a few.The rule asks for tabs and the files use spaces (or the reverse)Fix - 2
You fix a file, save, and the editor puts the other indentation back as you type.VS Code detects indentation and re-indents with the wrong styleFix - 3
You upgraded ESLint and formatting rules now come from two places.The rule is deprecated and a style plugin takes overFix
- 1
What does the error look like?
Expected indentation of 1 tab but found 4 spaces indentExpected indentation of 4 spaces but found 1 tab indent
Cause 1 of 3
The rule asks for tabs and the files use spaces (or the reverse)
1Check
The indent rule takes a number for spaces or the string tab. ESLint documents a default of 4 spaces when no value is given.
grep -rn "indent" eslint.config.* .eslintrc* 2>/dev/null2Fix
Set the value to the style your files use, or keep the rule and convert the files. Many problems this rule reports can be fixed automatically.
// eslint.config.js
export default [
{ rules: { indent: ['error', 2] } }, // or ['error', 'tab']
]3Verify
Run ESLint with the fix option, then lint again and see no indent errors.
npx eslint --fix .
npx eslint .Confirmed by eslint.org
Cause 2 of 3
VS Code detects indentation and re-indents with the wrong style
1Check
VS Code auto-detects each file's indentation, and the detected value overrides your default settings.
# VS Code shows the detected indentation on the right side of the status bar2Fix
Set the editor to your project's style, and turn off detection if you want your settings to win. Use the status bar entry to convert a file.
// .vscode/settings.json
{
"editor.detectIndentation": false,
"editor.insertSpaces": true,
"editor.tabSize": 2
}3Verify
Add a new indented line and lint the file.
npx eslint src/index.jsConfirmed by code.visualstudio.com
Cause 3 of 3
The rule is deprecated and a style plugin takes over
1Check
ESLint deprecated this rule in v8.53.0 and plans to remove it in v11.0.0. It points to the matching rule in @stylistic/eslint-plugin.
npm ls eslint @stylistic/eslint-plugin2Fix
Move the indent setting to the stylistic plugin, or hand formatting to a formatter and drop the rule.
npm install --save-dev @stylistic/eslint-plugin
// eslint.config.js
import stylistic from '@stylistic/eslint-plugin'
export default [{ plugins: { '@stylistic': stylistic }, rules: { '@stylistic/indent': ['error', 2] } }]3Verify
Remove the old rule, lint again, and confirm only one indent rule reports.
npx eslint .Confirmed by eslint.org
How do I stop it coming back?
- Write the indent style in the repository: ESLint rule and editor settings agree.
- Run eslint --fix in a pre-commit step so style drift never builds up.
- Use one tool for formatting; do not let two tools set indentation.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ng serve cannot find the dev-server builder package
Could not find the implementation for builder @angular/build:dev-server
The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.
3 causes, each with a fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix