简体   繁体   English

插件“react”在“.eslintrc.js”和“BaseConfig”之间发生冲突

[英]Plugin "react" was conflicted between ".eslintrc.js" and "BaseConfig

在此处输入图像描述

After I set up ESLint, I got this error Plugin "react" was conflicted between ".eslintrc.js" and "BaseConfig » /frontend/node_modules/react-scripts/node_modules/eslint-config-react-app/base.js".设置 ESLint 后,出现此错误Plugin "react" was conflicted between ".eslintrc.js" and "BaseConfig » /frontend/node_modules/react-scripts/node_modules/eslint-config-react-app/base.js" .

my.eslintrc.js is like my.eslintrc.js 就像

module.exports = {
  env: {
    browser: true,
    es2021: true,
  },
  extends: [
    'plugin:react/recommended',
    'airbnb',
    'airbnb/hooks',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
    'prettier',
  ],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
    ecmaVersion: 'latest',
    sourceType: 'module',
    tsconfigRootDir: __dirname,
    project: ['./tsconfig.json'],
  },
  plugins: [
    'react',
    '@typescript-eslint',
  ],
  ignorePatterns: [
    ".eslintrc.js"
  ],
  rules: {
    'no-use-before-define': "off",
    "@typescript-eslint/no-use-before-define": "off",
    'import/prefer-default-export': "off",
    'import/extensions': [
      'error',
      {
        js: 'never',
        jsx: 'never',
        ts: 'never',
        tsx: 'never',
      },
    ],
    'react/jsx-filename-extension': [
      'error',
      {
        extensions: ['.jsx', '.tsx'],
      },
    ],
    'react/react-in-jsx-scope': 'off',
    'no-void': [
      'error',
      {
        allowAsStatement: true,
      },
    ],
    "react/function-component-definition": [
      2,
      { "namedComponents": "arrow-function" }
    ]
  },
  settings: {
    'import/resolver': {
      node: {
        paths: ['src'],
        extensions: ['.js', '.jsx', '.ts', '.tsx']
      },
    },
  },
};

What I have done is我所做的是

  • npx create-react-app my-app --template typescript npx create-react-app my-app --template typescript
  • yarn run eslint --init纱线运行 eslint --init
  • yarn add -D @typescript-eslint/eslint-plugin @typescript-eslint/parser纱线添加-D @typescript-eslint/eslint-plugin @typescript-eslint/parser
  • npx install-peerdeps --dev eslint-config-airbnb npx install-peerdeps --dev eslint-config-airbnb

How can I remove this error?我怎样才能消除这个错误?

您可能需要在您的锁定文件中对 eslint-plugin-react 进行重复数据删除。

You have to disable eslint while react-scripts start .你必须在react-scripts start时禁用 eslint。

As of react-scripts v4.0.2, you can now opt out of ESLint with an environment variable.react-scripts v4.0.2 开始,您现在可以使用环境变量选择退出 ESLint。 You can do this by adding it to your .env file, or by prefixing your scripts in your package.json file.您可以通过将其添加到您的.env文件,或在您的 package.json 文件中添加脚本前缀来实现。

For example in .env :例如在.env中:

DISABLE_ESLINT_PLUGIN=true

I fixed the issue by closing and reopening the project folder with code.我通过使用代码关闭并重新打开项目文件夹来解决此问题。 There must have been a problem with the path name.路径名一定有问题。

Hope this helps:)希望这可以帮助:)

I fixed this problem in this way: if you are using npm remove the package-lock.json file.我以这种方式解决了这个问题:如果您使用的是 npm,请删除 package-lock.json 文件。 if you are using the yarn remove the yarn.lock file.如果您使用纱线,请删除 yarn.lock 文件。

and then remove the node_module folder and install all of the dependencies again.然后删除 node_module 文件夹并再次安装所有依赖项。

yarn remove eslint-config-react-app yarn add eslint-config-react-app@6 yarn remove eslint-config-react-app yarn add eslint-config-react-app@6

yarn run eslint --initc纱线运行 eslint --initc
//Reinicia la configuracion de eslist y permite que //automaticamente coloque los paquetes q falten //Reinicia la configuracion de eslist y permite que //automaticamente coloque los paquetes q falten

// quita los errores automaticamente con . //quita los errores automaticamente con . y --fix y --修复

npx eslint . npx eslint 。 --fix - 使固定

Been there too, and finding the exact answer to this issue is hard to find.也去过那里,很难找到这个问题的确切答案。

The best solution for now is to remove eslintrc.json .目前最好的解决方案是删除eslintrc.json

I faced the same error.我遇到了同样的错误。 After trying every solution I found on the inte.net, removing eslintrc.js actually helped.在尝试了我在 inte.net 上找到的所有解决方案后,删除 eslintrc.js 实际上有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Create-react-app - 插件“react”中的错误在“.eslintrc.json”和“BaseConfig”之间发生冲突 - Create-react-app - ERROR in Plugin "react" was conflicted between ".eslintrc.json" and "BaseConfig" 插件“反应”在“package.json ...”和“BaseConfig ...”之间发生冲突 - Plugin "react" was conflicted between "package.json ..." and "BaseConfig ..." React Native 中的“.eslintrc.js”是什么? - What is “.eslintrc.js” in React Native? .eslintrc.js 用于 React 17 和 JSX,无需导入“react” - .eslintrc.js for React 17 and JSX without import 'react' Eslint 插件“反应”在 eslintrc.json >> eslint-config-airbnb 之间发生冲突 - Eslint Plugin "react"was conflicted between .eslintrc.json >> eslint-config-airbnb ESLint:插件“反应”在两者之间发生冲突 - ESLint: Plugin "react" was conflicted between 在已经使用和扩展“eslint-config-airbnb”的同时,我是否必须在 eslintrc.js 配置中使用和“扩展”eslint-plugin-react - Do I have to use and 'extend' eslint-plugin-react in eslintrc.js config while using and extending 'eslint-config-airbnb' already 插件“react”中的错误在 - ERROR in Plugin "react" was conflicted between 插件“react”在“package.json”之间发生冲突 - Plugin "react" was conflicted between "package.json process.node.env 在 eslintrc.js 中未定义 - process.node.env is undefined in eslintrc.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM