ESLint fails with 'No Babel config file detected'
Parsing error: No Babel config file detectedShort answer
@babel/eslint-parser needs a Babel configuration file by default. The error means Babel found none from where ESLint is running. Either add a babel.config.json at the project root, run ESLint from that root, or set requireConfigFile to false and give the parser its own babelOptions.
Fix it fast
1Find out which cause you have
Look for a Babel config in the folder ESLint runs from. Babel searches the current working directory as its root.
pwd ls babel.config.* .babelrc*2Match what you see, then jump to its fix
What does the error look like?
Parsing error: No Babel config file detectedESLint stops on a file before any rule runs
Cause 1 of 2
The project has no Babel config file
1Check
The parser requires @babel/core and a valid Babel configuration file.
npm ls @babel/core @babel/eslint-parser2Fix
Tell the parser not to require one and give it options directly, as the ESLint docs show. Or create babel.config.json instead.
// eslint.config.js
import babelParser from "@babel/eslint-parser";
export default [
{
languageOptions: {
parser: babelParser,
parserOptions: {
requireConfigFile: false,
babelOptions: { presets: ["@babel/preset-env"] },
},
},
},
];3Verify
ESLint parses the files.
npx eslint srcConfirmed by eslint.org
Cause 2 of 2
ESLint runs from a sub-folder, so Babel misses the root config
1Check
Babel treats the working directory as its root. A babel.config.json in a parent folder is not seen unless you ask for it.
pwd
ls ../babel.config.*2Fix
Run ESLint from the folder that holds the config, or set rootMode to upward so Babel searches parent folders.
parserOptions: {
babelOptions: { rootMode: "upward" },
}3Verify
Lint the same file again.
npx eslint src/main.jsConfirmed by babeljs.io
How do I stop it coming back?
- Keep one Babel config at the project root and run lint scripts from there.
- Document the lint command in package.json scripts, not in editor settings.
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