Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Node 22 - "Could not find exported rules object in ESLint plugin." error #615

Open
marcalexiei opened this issue Jan 12, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@marcalexiei
Copy link

I have updated Node to v22.x and I started to get Could not find exported rules object in ESLint plugin. error.

Note

I'm able to reproduce the issue only using Node 22.13.0.
On Node 20.17.0 the issue is not present.

This PR contains a successful run and a failed run to show the issue
You can check node version inside "Install dependencies" step

Steps to reproduce the issue

  1. Download / clone the example repository
  2. Use Node 20
  3. Run pnpm install
  4. Run pnpm run lint:docs, no error should be present
  5. Switch to Node 22 (I use nvm)
  6. Run pnpm run lint:docs, the error should be present

Initial investigation

From my initial investigation the problem seems originated from loadPlugin function:

export async function loadPlugin(path: string): Promise<Plugin> {

Inside the require() try for CommonJS

try {
// Try require first which should work for CJS plugins.
return require(pluginRoot) as Plugin; // eslint-disable-line import/no-dynamic-require
} catch (error) {
// Otherwise, for ESM plugins, we'll have to try to resolve the exact plugin entry point and import it.

On Node 20 the require throws an error and the code inside the catch is executed.

On the contrary, on Node 22 the require doesn't throw an error, and the plugin module is resolved.
However the module itself is an ESModule, so instead of the plugin object the loadPlugin function
returns a { __esModule: true, default: { /** plugin */ } }

I attached a screenshot of the debugger in this scenario

image

@bmish bmish added the bug Something isn't working label Jan 13, 2025
@marcalexiei
Copy link
Author

I removed the main field from package.json and the issue is no longer present in Node 22,
and, same as previously, no issue is present on Node 20.

Maybe this change is related to Support require()ing synchronous ESM graphs of Node 22...
but this should be enabled only when using the experimental flag which isn't the case here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants