Skip to content

fix(next-codemod): handle CommonJS legacy ESLint configs in next-lint…#95710

Open
Alexoswin wants to merge 1 commit into
vercel:canaryfrom
Alexoswin:fix/next-lint-codemod-legacy-js-config
Open

fix(next-codemod): handle CommonJS legacy ESLint configs in next-lint…#95710
Alexoswin wants to merge 1 commit into
vercel:canaryfrom
Alexoswin:fix/next-lint-codemod-legacy-js-config

Conversation

@Alexoswin

Copy link
Copy Markdown

What?

The next-lint-to-eslint-cli codemod assumed that @eslint/migrate-config always generates eslint.config.mjs. In practice, the migration tool preserves the module format of JavaScript-based legacy configs:

  • .eslintrc.jseslint.config.js
  • .eslintrc.cjseslint.config.cjs

Because of this assumption, the codemod failed with:

Failed to find the expected output file

when migrating projects using CommonJS ESLint configs.

This change detects whichever flat config file was actually generated instead of hardcoding eslint.config.mjs. It also preserves the module system when updating CommonJS configs by generating require() declarations instead of ESM import statements.

Why?

next lint has been removed in Next.js 16, making this codemod the recommended migration path. Projects using .eslintrc.js or .eslintrc.cjs currently cannot complete the migration because the codemod crashes before finishing.

Additionally, even if the generated file were found, the previous implementation would have inserted ESM imports into a CommonJS config, resulting in an invalid ESLint configuration.

How?

  • Detect the generated flat config (.mjs, .js, or .cjs) instead of assuming a fixed filename.
  • Detect whether the generated config is CommonJS.
  • Generate require() declarations for CommonJS configs while preserving the existing ESM behavior for .mjs configs.
  • Update the FlatCompat replacement logic to work correctly for CommonJS output.
  • Add a regression test covering migration from a .eslintrc.cjs configuration.

Testing

  • Added a regression test for .eslintrc.cjs migration.
  • Verified the new test reproduces the reported failure before the fix and passes afterward.
  • Ran the full next-codemod test suite successfully.
  • Verified the generated eslint.config.cjs works with ESLint 9 in a real sample project.

Fixes #85679

…-to-eslint-cli

The next-lint-to-eslint-cli codemod assumed @eslint/migrate-config always
generates eslint.config.mjs. The migration tool actually keeps the
extension of JS legacy configs (.eslintrc.js -> eslint.config.js,
.eslintrc.cjs -> eslint.config.cjs), so the codemod crashed with
"Failed to find the expected output file" for those formats.

Detect the generated flat config instead of hardcoding the .mjs name,
and emit require() declarations instead of ESM import statements when
updating a CommonJS flat config so the result stays loadable.

Fixes vercel#85679
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken next-lint-to-eslint-cli codemod

1 participant