Limits of recovering from a failed ESLint Flat Config upgrade
0 reputation · 20 Apr 2023, 17:17 UTC
0 reputation · 20 Apr 2023, 17:17 UTC
When upgrading to the Flat Config system in ESLint 8+, a mis‑configured eslint.config.js can cause linting to fail or produce incorrect results. The project may still rely on a working legacy .eslintrc hierarchy, but the presence of the new file overrides it. The goal is to recover the previous state without manual rewrites or loss of plugin compatibility.
Constraints include: the project has already been built with the new config, some plugins are imported as objects, and the legacy config uses string references. There is no built‑in “undo” command in ESLint, and the migration is a breaking change that may affect CI pipelines.
Questions:
eslint.config.js and fall back to the legacy .eslintrc hierarchy?32775 reputation · 20 Apr 2023, 18:51 UTC
No. When eslint.config.js is present and it throws an error, ESLint stops with a fatal message and does not try the legacy .eslintrc hierarchy. The tool treats the presence of a flat config file as a signal to use only that source.
ESLint does not expose a dedicated --legacy flag. However, two mechanisms let you force legacy parsing:
--config <file> – Point explicitly to a legacy .eslintrc.* file. This bypasses any eslint.config.js that may exist.
ESLINT_USE_FLAT_CONFIG=0 – Setting it to 0 disables flat‑config parsing entirely, making ESLint fall back to the traditional hierarchy even if a flat file is present.
mv eslint.config.js eslint.config.js.bak
export ESLINT_USE_FLAT_CONFIG=0
Or add it to your CI job definition.
npx eslint --print-config src/index.js | grep "extends" | head
The output should list the legacy .eslintrc files, not eslint.config.js.
"plugin:react/recommended", confirm eslint-plugin-react is in devDependencies. No changes are needed to the plugin import syntax.
npx eslint src/**/*.js should exit with 0 and report no configuration errors.
After these steps, CI pipelines that previously failed due to the broken flat config will resume using the legacy hierarchy without any manual rewrites. If you later wish to re‑enable flat config, simply restore eslint.config.js and unset the environment variable.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.