Skip to content

Conversation

@rajnish93
Copy link

What?

Refactored the exports in packages/eslint-plugin-next/src/index.ts to explicitly assign named exports (configs, rules, meta) to module.exports in a way that is statically analyzable by Node.js's CJS-ESM interop (specifically cjs-module-lexer).

Why?

Fixes #86504

When importing @next/eslint-plugin-next in an ESM environment (like eslint.config.js or using node -e "import ..."), named imports such as import { configs } from '@next/eslint-plugin-next' were failing.

This happened because swc compiles the previous export const syntax into Object.defineProperty getters. While valid CommonJS, Node.js's cjs-module-lexer cannot detect these dynamic getters as named exports, leading to a runtime error: SyntaxError: Named export 'configs' not found.

How?

I updated the entry point (src/index.ts) to:

  1. Directly assign module.exports = plugin for the default export.
  2. Explicitly assign exports.configs, exports.rules, and exports.meta as properties.

This pattern ensures that:

  • CommonJS consumers (using require) receive the expected plugin object with properties.
  • ESM consumers (using import) can successfully import named exports because cjs-module-lexer can now detect the exports.prop = ... pattern.

Verified the fix using the reproduction script from the issue:
node -e "import {configs} from '@next/eslint-plugin-next'; console.log(Object.keys(configs))"

Output: [ 'recommended-legacy', 'core-web-vitals-legacy', 'recommended', 'core-web-vitals' ]Fixes #86504

@ijjk
Copy link
Member

ijjk commented Nov 28, 2025

Allow CI Workflow Run

  • approve CI run for commit: 0ed46c1

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@rajnish93 rajnish93 force-pushed the fix/eslint-plugin-named-exports branch from 985b4d7 to 35d7e9e Compare November 28, 2025 21:20
@rajnish93 rajnish93 force-pushed the fix/eslint-plugin-named-exports branch from 35d7e9e to 234ff10 Compare November 28, 2025 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@next/eslint-plugin-next incorrect named exports

2 participants