Description
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
- Download / clone the example repository
- Use Node 20
- Run
pnpm install
- Run
pnpm run lint:docs
, no error should be present - Switch to Node 22 (I use nvm)
- Run
pnpm run lint:docs
, the error should be present
Initial investigation
From my initial investigation the problem seems originated from loadPlugin
function:
eslint-doc-generator/lib/package-json.ts
Line 35 in a88f8cb
Inside the require()
try
for CommonJS
eslint-doc-generator/lib/package-json.ts
Lines 37 to 41 in a88f8cb
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 */ } }