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]: Key "plugins": Cannot redefine plugin "react" #3765

Closed
2 tasks done
tiavina-mika opened this issue Jun 10, 2024 · 10 comments
Closed
2 tasks done

[Bug]: Key "plugins": Cannot redefine plugin "react" #3765

tiavina-mika opened this issue Jun 10, 2024 · 10 comments
Labels

Comments

@tiavina-mika
Copy link

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

I have this error when runing eslint: Key "plugins": Cannot redefine plugin "react"

here is my eslint.confi.js

import path from 'path';
import { fileURLToPath } from 'url';
import js from "@eslint/js";
import tseslint from 'typescript-eslint';
import react from 'eslint-plugin-react';
import globals from 'globals';
import reactRecommended from 'eslint-plugin-react/configs/recommended.js';


const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory


export default tseslint.config(
  js.configs.recommended,
  reactRecommended,
  {
    files: ["**/*.ts", "**/*.tsx"],
    languageOptions: {
      ecmaVersion: 2022,
      // parser: "@typescript-eslint/parser"
      parser: tseslint.parser,
      parserOptions: {
        sourceType: "module",
        project: true,
        tsconfigRootDir: __dirname,
        ecmaFeatures: {
          jsx: true,
        },
        globals: {
          ...globals.browser,
        },
      },
    },
    plugins: {
      react,
    },
    rules: {},
    ignores: [
      "node_modules/",
    ],
  },
);

Expected Behavior

Should have no errors

eslint-plugin-react version

7.34.2

eslint version

9.4.0

node version

20.22.0

@bsal649
Copy link

bsal649 commented Jun 10, 2024

ESLint v9 isn't supported yet. Either roll back to 8.57 or you can try working around it with @eslint/compat, but that's not guaranteed to work.

@mdjermanovic
Copy link
Contributor

I have this error when runing eslint: Key "plugins": Cannot redefine plugin "react"

This happens because eslint-plugin-react's flat configs have their own plugins.react object that, although functionally the same, is not the same instance as react in import react from 'eslint-plugin-react'.

A quick fix in your eslint.config.js would be to remove one of these two plugin definitions:

-     plugins: {
-       react,
-     },

Nevertheless, I think that eslint-plugin-react should be fixed so that it always uses the same plugin object.

@ljharb
Copy link
Member

ljharb commented Jun 12, 2024

@mdjermanovic what would be the impact of that change?

@ljharb
Copy link
Member

ljharb commented Jun 12, 2024

Either way, closing, because you simply can't use eslint 9 with a plugin that doesn't declare peerDep compatibility with it.

Wait to upgrade eslint until all your things support it explicitly.

@ljharb ljharb closed this as not planned Won't fix, can't repro, duplicate, stale Jun 12, 2024
@mdjermanovic
Copy link
Contributor

@mdjermanovic what would be the impact of that change?

This can be fixed in a way that wouldn't be a breaking change for eslint-plugin-react. We could include the fix in #3759.

Note that this isn't eslint 9 specific. the same problem exists with eslint-plugin-react + eslint 8 flat config.

@ljharb
Copy link
Member

ljharb commented Jun 12, 2024

Thanks; in that case let's land it in its own PR?

@mdjermanovic
Copy link
Contributor

Thanks; in that case let's land it in its own PR?

Makes sense, I can prepare a separate PR for this issue.

I mentioned #3759 because it adds tests with flat configs (ef6f9c5 for the start) which seem particularly useful for this problem, but those tests can be extracted into the other PR and run with eslint >= 8.57.0 instead of just >= 9.

@ljharb
Copy link
Member

ljharb commented Jun 12, 2024

Also perhaps #3694 is a good fit for it.

@mdjermanovic
Copy link
Contributor

Also perhaps #3694 is a good fit for it.

Hm, yes, I didn't see that. The issue it references (#3693) is the same as this one. But there's a question of what to do with existing exports (eslint-plugin-react/configs/recommended and others)?

@ljharb
Copy link
Member

ljharb commented Jun 12, 2024

The existing imports would need to keep working the same for eslintrc users. I'm not sure what that would entail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants