Skip to content

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

Closed
@marcalexiei

Description

@marcalexiei

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions