Skip to content

Bug: Error using eslint-plugin-react-compiler in a TypeScript config (eslint.config.ts) #19413

@brandongit2

Description

@brandongit2

Environment

Node version: v23.1.0
npm version: v10.9.0
Local ESLint version: v9.20.0 (Currently used)
Global ESLint version: Not found
Operating System: darwin 24.2.0

What parser are you using?

Default (Espree)

What did you do?

Repro: https://github.com/brandongit2/eslint-jiti-bug-repro

Steps:

  1. Clone the repository above
  2. pnpm install in the cloned repo
  3. pnpm lint to run ESLint
  4. Error:
    Image

What did you expect to happen?

I expected the file to lint successfully.

What actually happened?

TypeError: Cannot read properties of undefined (reading 'configs')

Link to Minimal Reproducible Example

https://github.com/brandongit2/eslint-jiti-bug-repro

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

I was able to track down the issue to this line:

const jiti = createJiti(__filename, { moduleCache: false, interopDefault: false });

Setting interopDefault: true fixes the exception.

Reason for the exception:

  1. eslint-plugin-react-compiler is a pure-CJS library
  2. ESLint loads TypeScript configs with Jiti
  3. Jiti uses @babel/plugin-transform-modules-commonjs during its Babel transform step
  4. When your config-loader.js sets interopDefault: false, the Babel plugin turns off its importInterop setting which breaks the eslint-plugin-react-compiler import (info on the importInterop setting)
  5. That Babel plugin rewrites all references to default imports. So when I do import reactCompiler from 'eslint-plugin-react-compiler', every reference to reactCompiler in the config becomes reactCompiler.default.
  6. The .default property doesn't exist on that import, hence Cannot read properties of undefined (reading 'configs') when I try to access reactCompiler.configs.recommended.

This PR in the Jiti repo mentions how the interopDefault setting is important in many cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugESLint is working incorrectlyrepro:yesIssues with a reproducible example

    Type

    Projects

    Status

    Complete

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions