jsx-eslint/eslint-plugin-react

[Bug]: The latest version is giving a ESLint error (No default export found in imported module)

Open

#3837 opened on Oct 1, 2024

View on GitHub
 (7 comments) (0 reactions) (0 assignees)JavaScript (8,630 stars) (2,797 forks)batch import
bughelp wantedtypescript

Description

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

Hi team!

First, thanks a lot for the hard work on this library.

The latest version of eslint-plugin-react includes the types for the project, but unfortunately, the types seem to be incorrect.

We're using the plugin eslint-plugin-import-x, which we're also using to validate our ESLint configuration, and this plugin is giving us the following error:

ESLint: No default export found in imported module "eslint-plugin-react". (import-x/default)

The complete output:

❯ pnpm eslint --cache .

/src/react.js
   3:8  error    No default export found in imported module "eslint-plugin-react"  import-x/default

✖ 1 problems (1 error)

The error occurs on the following line:

import react from "eslint-plugin-react";

I then tried to use a named export instead of the default export, as the ESLint rule suggests, but this doesn't seem to work as I'm getting the following error:

SyntaxError: Named export 'configs' not found. The requested module 'eslint-plugin-react' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

The JavaScript is using a module.exports statement, as shown here:

https://github.com/jsx-eslint/eslint-plugin-react/blob/master/index.js#L109

However, the index.d.ts exports a single configs namespace that doesn't reflect the code specified in the index.js-file. You can see this by inspecting the index.d.ts file on npmjs.com

https://www.npmjs.com/package/eslint-plugin-react?activeTab=code

Expected Behavior

I'd expect that the TypeScript types reflect the module.exports statement of the index.js file 1:1

eslint-plugin-react version

v7.37.1

eslint version

v9.11.1

node version

v20.17.0

Contributor guide