fix(eslint-plugin-next): ensure named exports for ESM compatibility #86620
+51
−34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Refactored the exports in
packages/eslint-plugin-next/src/index.tsto explicitly assign named exports (configs,rules,meta) tomodule.exportsin a way that is statically analyzable by Node.js's CJS-ESM interop (specificallycjs-module-lexer).Why?
Fixes #86504
When importing
@next/eslint-plugin-nextin an ESM environment (likeeslint.config.jsor usingnode -e "import ..."), named imports such asimport { configs } from '@next/eslint-plugin-next'were failing.This happened because
swccompiles the previousexport constsyntax intoObject.definePropertygetters. While valid CommonJS, Node.js'scjs-module-lexercannot 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:module.exports = pluginfor the default export.exports.configs,exports.rules, andexports.metaas properties.This pattern ensures that:
require) receive the expected plugin object with properties.import) can successfully import named exports becausecjs-module-lexercan now detect theexports.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