简体   繁体   English

Create-react-app - 插件“react”中的错误在“.eslintrc.json”和“BaseConfig”之间发生冲突

[英]Create-react-app - ERROR in Plugin "react" was conflicted between ".eslintrc.json" and "BaseConfig"

After updating to CRA 5.0.0, I got this error on compilation process:更新到 CRA 5.0.0 后,我在编译过程中遇到了这个错误:

ERROR in Plugin "react" was conflicted between ".eslintrc.json" and "BaseConfig » "..\react-app\node_modules\eslint-config-react-app\base.js".

My eslint configuration is:我的 eslint 配置是:

{
    "env": {
        "browser": true,
        "es2021": true
    },
    "extends": [
        "plugin:react/recommended",
        "airbnb",
        "plugin:react/jsx-runtime"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "plugins": [
        "react",
        "@typescript-eslint"
    ],
    "rules": {...}
}

Any solutions/fixes?任何解决方案/修复?

The problem :问题

eslint-plugin-react version in your project's dependency is "different" from the one in eslint-config-react-app package's dependency, hence "conflicting".项目依赖项中的eslint-plugin-react版本与eslint-config-react-app包依赖项中的版本“不同”,因此是“冲突的”。

The solution :解决方案

Avoid deleting the .lock file as many suggested here ( it's there for a reason ).避免像这里建议的那样删除.lock文件(它的存在是有原因的)。 Instead, dedupe its entries and then re-install.相反,删除其条目,然后重新安装。

npm : npm

npm dedupe && npm i

yarn :纱线

npx yarn-deduplicate && yarn

Well, this seems to be related to one of the following issues.嗯,这似乎与以下问题之一有关。

https://github.com/yannickcr/eslint-plugin-react/issues/3128https://github.com/yannickcr/eslint-plugin-react/issues/3128

https://github.com/facebook/create-react-app/issues/10463 https://github.com/facebook/create-react-app/issues/10463

What you can try is the following (if the first one does not work, try the second one, if you are using yarn):您可以尝试以下方法(如果第一个不起作用,请尝试第二个,如果您使用的是 yarn):

In addition, take a look the CRA release notes to check if some action is required, especially the part about "Migrating from 4.0.x to 5.0.0" , you may need to update react-scripts as well.此外,请查看 CRA 发行说明以检查是否需要执行某些操作,尤其是有关“从 4.0.x 迁移到 5.0.0”的部分,您可能还需要更新react-scripts

https://github.com/facebook/create-react-app/releases/tag/v5.0.0 https://github.com/facebook/create-react-app/releases/tag/v5.0.0

This probably won't help OP, but in my case, I'd updated my react app to MUI 5 and eslint from ^7.32.0 to ^8.7.0 but I forgot to upgrade eslint-plugin-react and eslint-plugin-react-hooks and the above error was happening on file change on reload.这可能对 OP 没有帮助,但就我而言,我已将我的 react 应用程序更新为 MUI 5,并将 eslint 从^7.32.0^8.7.0 ,但我忘记升级eslint-plugin-reacteslint-plugin-react-hooks和上述错误发生在重新加载文件更改时。 Upgrading them to ^7.28.0 and ^4.3.0 respectively fixed my problem.将它们分别升级到^7.28.0^4.3.0解决了我的问题。

I just ran the npm install --dev eslint-config-react-app command and the error is gone.我刚刚运行了npm install --dev eslint-config-react-app命令,错误就消失了。 Also use --include=dev instead of --dev .也使用 --include --include=dev而不是--dev

also install dev dependencies with below command:还使用以下命令安装开发依赖项:

npm install --save-dev eslint-config-react-app eslint@^8.0.0

Then create a file named .eslintrc.json with following contents in the root folder of your project:然后在项目的根文件夹中创建一个名为.eslintrc.json的文件,其内容如下:

{
  "extends": "react-app"
}

Source https://www.npmjs.com/package/eslint-config-react-app来源https://www.npmjs.com/package/eslint-config-react-app

What solved this for me was making sure that the path I cd into from the terminal has the same exact capitalization as the real path.为我解决这个问题的是确保我从终端 cd 进入的路径与实际路径具有相同的大小写。

I think it's because of not an updated eslint.我认为这是因为没有更新的 eslint。 Just changing the eslint version to 8.0.0 from 7.0.0 in your package.json worked for me or you update in your cli using npm.只需将 eslint 版本从 package.json 中的 7.0.0 更改为 8.0.0 对我有用,或者您使用 ZBB30E85411B56DF41296726AB445DCF 在 cli 中更新

from package.json I removed:从 package.json 我删除了:

"eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  }

Then, I restarted the server with npm start and my web app is working again.然后,我用npm start重新启动了服务器,我的网络应用程序再次运行。

Hope it can help希望能帮到你

I just tried to use your config in my project (which is working with CRA 5.0.0) and didn't receive this error.我只是尝试在我的项目(与 CRA 5.0.0 一起使用)中使用您的配置,但没有收到此错误。 I think the problem is that you didn't update one or several eslint-related packages.我认为问题在于您没有更新一个或几个与 eslint 相关的软件包。 You can try to update them:您可以尝试更新它们:

yarn add -D \
eslint@^8.6.0 \
@typescript-eslint/eslint-plugin@^5.9.0 \
@typescript-eslint/parser@^5.9.0 \
eslint-plugin-react@^7.28.0 \
eslint-config-react@^1.1.7 \
eslint-config-airbnb@^19.0.4

or npm install instead of yarn add if you are using npmnpm install而不是yarn add

I've just downgraded eslint-config-react-app from version 7.0.0 to 6.0.0 :我刚刚将eslint-config-react-app从版本7.0.0降级到6.0.0

yarn add --dev eslint-config-react-app@6.0.0 

or或者

npm install --dev eslint-config-react-app@6.0.0 

Maybe this will help someone.也许这会对某人有所帮助。

For me it worked after updating对我来说,更新后它起作用了

"eslint-plugin-react": "7.29.4",
"eslint-plugin-jsx-a11y": "6.5.1"

removing package-lock.json and node_modules and reinstalling the package.删除package-lock.jsonnode_modules并重新安装 package。

Simply updating eslint-plugin-react from version 7.28.x to 7.29.x worked for me只需将 eslint-plugin-react 从版本 7.28.x 更新到 7.29.x 对我有用

Before trying the previous responses.在尝试先前的响应之前。 just open your package.json file and save it by Cntrl + S and run your app again it worked for me.只需打开您的package.json文件并通过Cntrl + S保存并再次运行您的应用程序,它对我有用。

If using yarn, delete your yarn.lock and run:如果使用 yarn,请删除您的yarn.lock并运行:

yarn install

This will rebuild the.lock file and the error will go away.这将重建 .lock 文件,错误将 go 消失。

I was able to fix this issue by the use of env variables.我能够通过使用环境变量来解决这个问题。

I installed eslint as a dev-dependency (as well all any other plugins you that i use).我将 eslint 安装为开发依赖项(以及我使用的所有其他插件)。

To get your code to lint, but not fail, in development, add this to your.env.development: ESLINT_NO_DEV_ERRORS = true要让您的代码在开发中进行 lint,但不会失败,请将其添加到 your.env.development: ESLINT_NO_DEV_ERRORS = true

To completely disable eslint on a production build, add this to your.env.production: DISABLE_ESLINT_PLUGIN = true要在生产版本中完全禁用 eslint,请将其添加到 your.env.production: DISABLE_ESLINT_PLUGIN = true

What's terminal do you use?你用什么终端? I don't recommend Windows PowerShell.我不推荐 Windows PowerShell。 Use the PowerShell new version and will works fine.使用 PowerShell 新版本可以正常工作。

See the image of Powershell I recommended看图片 Powershell 我推荐

Today i ran into the problem and after i ran an audit fix--force the npm start didnt work but i got a lovely long message which explains the steps and also the reason behind this.今天我遇到了这个问题,在我运行审计修复后——强制 npm 启动没有用,但我收到了一条可爱的长消息,解释了这些步骤以及背后的原因。 I found it helpful and fixed my problem.我发现它很有帮助并解决了我的问题。

There might be a problem with the project dependency tree.项目依赖树可能有问题。 It is likely not a bug in Create React App, but something you need to fix locally.这可能不是 Create React App 中的错误,而是您需要在本地修复的错误。

The react-scripts package provided by Create React App requires a dependency: Create React App 提供的 react-scripts package 需要依赖:

"eslint": "5.6.0" “eslint”:“5.6.0”

Don't try to install it manually: your package manager does it automatically.不要尝试手动安装:您的 package 管理器会自动安装。 However, a different version of eslint was detected higher up in the tree:但是,在树的较高位置检测到不同版本的 eslint:

C:\Users\rohad\Desktop\project\node_modules\eslint (version: 8.10.0) C:\Users\rohad\Desktop\project\node_modules\eslint(版本:8.10.0)

Manually installing incompatible versions is known to cause hard-to-debug issues.众所周知,手动安装不兼容的版本会导致难以调试的问题。

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an.env file in your project.如果您希望忽略此检查,请将 SKIP_PREFLIGHT_CHECK=true 添加到项目中的 .env 文件中。 That will permanently disable this message but you might encounter other issues.这将永久禁用此消息,但您可能会遇到其他问题。

To fix the dependency tree, try following the steps below in the exact order:要修复依赖关系树,请尝试按确切顺序执行以下步骤:

  1. Delete package-lock.json (not package.json.) and/or yarn.lock in your project folder.删除项目文件夹中的 package-lock.json(不是 package.json。)和/或 yarn.lock。
  2. Delete node_modules in your project folder.删除项目文件夹中的 node_modules。
  3. Remove "eslint" from dependencies and/or devDependencies in the package.json file in your project folder.从项目文件夹中 package.json 文件中的依赖项和/或 devDependencies 中删除“eslint”。
  4. Run npm install or yarn, depending on the package manager you use.运行 npm install 或 yarn,具体取决于您使用的 package 管理器。

In most cases, this should be enough to fix the problem.在大多数情况下,这应该足以解决问题。 If this has not helped, there are a few other things you can try:如果这没有帮助,您可以尝试其他一些方法:

  1. If you used npm, install yarn ( http://yarnpkg.com/ ) and repeat the above steps with it instead.如果您使用 npm,请安装 yarn ( http://yarnpkg.com/ ) 并用它重复上述步骤。 This may help because npm has known issues with package hoisting which may get resolved in future versions.这可能会有所帮助,因为 npm 已知 package 提升问题,这些问题可能会在未来的版本中得到解决。

  2. Check if C:\Users\rohad\Desktop\project\node_modules\eslint is outside your project directory.检查 C:\Users\rohad\Desktop\project\node_modules\eslint 是否在您的项目目录之外。 For example, you might have accidentally installed something in your home folder.例如,您可能不小心在主文件夹中安装了一些东西。

  3. Try running npm ls eslint in your project folder.尝试在项目文件夹中运行 npm ls eslint。 This will tell you which other package (apart from the expected react-scripts) installed eslint.这将告诉您哪些其他 package(除了预期的反应脚本)安装了 eslint。

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an.env file in your project.如果没有其他帮助,请将 SKIP_PREFLIGHT_CHECK=true 添加到项目中的 .env 文件中。 That would permanently disable this preflight check in case you want to proceed anyway.如果您仍然想继续,这将永久禁用此预检检查。

PS We know this message is long but please read the steps above:-) We hope you find them helpful! PS 我们知道这条信息很长,但请阅读上面的步骤:-) 我们希望它们对您有所帮助!

In my case, everything was updated to the latest version, but still I got the same error.就我而言,一切都更新到了最新版本,但我仍然遇到同样的错误。

After I deleted the lock file it started working删除锁定文件后,它开始工作

I got this issue because I got duplicate and not coherent declarations in both .eslintrc.yml and package.json .我遇到了这个问题,因为我在.eslintrc.ymlpackage.json中都有重复且不一致的声明。 It seems that updating to CRA 5.0 added back in package.json the following:似乎更新到 CRA 5.0 在 package.json 中添加了以下内容:

"eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },

Strange tbh.奇怪的。

What I recently did and it works 100% is to create a new reat-app project (using CRA 5+), and move all the files and configurations inside that new folder.我最近所做的并且 100% 有效的是创建一个新的 reat-app 项目(使用 CRA 5+),并将所有文件和配置移动到该新文件夹中。

This is the solution that worked for me.这是对我有用的解决方案。

Removing the lock file only may not work for you.仅删除锁定文件可能对您不起作用。 You just need to remove some of the packages from eslint.你只需要从 eslint 中删除一些包。

So here is my list of dev dependencies in package.json which was causing the same error.所以这是我在 package.json 中的开发依赖项列表,它导致了同样的错误。

"devDependencies": {
    "@babel/eslint-parser": "7.17.0",
    "@babel/preset-react": "7.16.7",
    "eslint": "8.14.0",
    "eslint-config-airbnb": "18.2.0",
    "eslint-config-prettier": "8.5.0",
    "eslint-plugin-html": "6.2.0",
    "eslint-plugin-import": "2.26.0",
    "eslint-plugin-jsdoc": "39.2.8",
    "eslint-plugin-jsx-a11y": "6.5.1",
    "eslint-plugin-prettier": "4.0.0",
    "eslint-plugin-react": "7.29.4",
    "eslint-plugin-react-hooks": "4.4.0",
    "eslint-plugin-testing-library": "5.3.1",
    "husky": "7.0.4",
    "lint-staged": "12.4.0",
    "prettier": "2.6.2"
  }

and after removing which were not needed, here is the list of dependencies which worked for me在删除不需要的之后,这里是对我有用的依赖项列表

"devDependencies": {
    "@babel/eslint-parser": "7.17.0",
    "@babel/preset-react": "7.16.7",
    "eslint": "8.14.0",
    "eslint-config-airbnb": "18.2.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-config-react-app": "^7.0.1",
    "eslint-plugin-html": "^6.2.0",
    "eslint-plugin-jsdoc": "^39.3.0",
    "eslint-plugin-prettier": "^4.0.0",
    "husky": "7.0.4",
    "lint-staged": "12.4.0",
    "prettier": "2.6.2"
  }
  • Replace these in dev dependencies.在开发依赖项中替换这些。
  • Remove the lock file and node_modules删除锁定文件和 node_modules
  • run yarn/npm install again再次运行 yarn/npm install

good luck祝你好运

I kept running into this compilation error while deploying to Vercel.在部署到 Vercel 时,我一直遇到这个编译错误。 You can solve the issue by deleting.eslintrc file and then remove this part from your package.json: "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] },您可以通过删除 .eslintrc 文件来解决问题,然后从 package.json 中删除此部分: "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] },

Tried a lot of solutions, but in the end, disabling ESLint inside CRA solved it for me.尝试了很多解决方案,但最后,在 CRA 中禁用 ESLint 为我解决了这个问题。 I use ESLint in the IDE anyway, so don't need it there as well.无论如何,我在 IDE 中使用 ESLint,所以那里也不需要它。

This other thread helped: https://stackoverflow.com/a/70830899/5613884这个其他线程有帮助: https://stackoverflow.com/a/70830899/5613884

I was using eslint-config-import which was causing the same problem with me, just remove it and everything going to work fine.我正在使用 eslint-config-import 这对我造成了同样的问题,只需将其删除,一切都会正常工作。 so I think that (react/jsx-runtime) may the cause of the problem所以我认为(react/jsx-runtime)可能是问题的原因

It works fine for me when I add root: true inside the.eslintrc.JSON file.当我在 .eslintrc.JSON 文件中添加root: true时,它对我来说很好。

This link may help you more Click here此链接可能对您有更多帮助点击这里

This is not a big error you just need to run this command npm install --prefer-dedupe or You can also run this command npm config set prefer-dedupe true and your error will be solved.这不是一个大错误,您只需要运行此命令npm install --prefer-dedupe或您也可以运行此命令npm config set prefer-dedupe true并且您的错误将得到解决。 You might be thinking about prefer this is nothing this is just for the version.您可能正在考虑prefer这只是为了版本。 you can run like this also npm install dedupe by default it will install the new version okay!你也可以像这样运行npm install dedupe它会安装新版本好吧!

I hope you solved your error after this answer.我希望您在此答案后解决了您的错误。

Removing "plugin:react/recommended" and/or "plugin:react/jsx-runtime" from "extends" should fix it. "plugin:react/recommended" and/or "plugin:react/jsx-runtime" from "extends"应该可以修复它。

I tried running npx yarn-deduplicate && yarn as suggested by @glenn-mohammad, put I only got SyntaxError.我尝试按照@glenn-mohammad 的建议运行npx yarn-deduplicate && yarn ,但我只得到 SyntaxError。 If you use yarn 2, try instead to run如果您使用 yarn 2,请尝试运行

yarn dedupe

See https://yarnpkg.com/cli/dedupe for docs.有关文档,请参阅https://yarnpkg.com/cli/dedupe

First time I ran it, I ran it on all packages, and it caused a new error with babel.我第一次运行它时,我在所有包上运行它,它导致了 babel 的新错误。 If that happens to you, try instead to run it only on the packages with issues.如果您遇到这种情况,请尝试只在有问题的包上运行它。

The issue I was facing is a bit different but I am going to post this answer here because the google search for my issue takes me to this page:我面临的问题有点不同,但我会在这里发布这个答案,因为谷歌搜索我的问题会将我带到这个页面:

Short answer:简短回答:

Watch for casing differences in the folder structure, if the project is inside a .net project.如果项目在 .net 项目中,请注意文件夹结构中的大小写差异。

Long answer长答案

The set up:设置:

We have a react app using create react app hosted inside a .net core project.我们有一个使用托管在 .net 核心项目中的 create react app 的 React 应用程序。 So when a run project build is done for the first time visual studio runs npm install and then npm start.因此,当第一次运行项目构建完成时,visual studio 运行 npm install,然后运行 npm start。 The page opens up and an error is thrown页面打开并抛出错误

The error:错误:

[eslint] Plugin "react" was conflicted between "package.json » eslint-config-react-app » C:\test folder\New folder\src\WatchCasing\ClientApp\node_modules\eslint-config-react-app\base.js" and "BaseConfig » C:\test folder\New folder\src\watchCasing\ClientApp\node_modules\eslint-config-react-app\base.js".

Look at the "watchCasing" folder name its different, one is WatchCasing and the other is watchCasing.“watchCasing”文件夹名字不一样,一个是WatchCasing,一个是watchCasing。 I obviously missed this casing difference until I read this github answer: github answer在我阅读这个 github 答案之前,我显然错过了这个大小写差异: github answer

Cause and solution:原因及解决方法:

Root cause of the issue was that the solution file(.sln) had the wrong casing(because some one did an improper rename) but the project built fine since windows treats file as case insensitive.问题的根本原因是解决方案文件 (.sln) 的大小写错误(因为有人做了不正确的重命名)但项目构建良好,因为 Windows 将文件视为不区分大小写。

The problem was solved by fixing the casing in the solution file to match the casing of the actual folder in the project section.通过修复解决方案文件中的大小写以匹配项目部分中实际文件夹的大小写,问题得以解决。

Project("{project-guid}") = "project.name", "watchCasing\project.name.csproj", "{different-guid}"

EndProject结束项目

Using the correct capitalization to cd in from is what worked for me.使用正确的大写从 cd in from 对我有用。

IE If real path is /Documents/Websites/EXAMPLE/ex1 then don't cd in with /Documents/Websites/example/ex1 IE 如果真实路径是 /Documents/Websites/EXAMPLE/ex1 则不要使用 /Documents/Websites/example/ex1 cd in

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

相关问题 插件“react”在“.eslintrc.js”和“BaseConfig”之间发生冲突 - Plugin "react" was conflicted between ".eslintrc.js" and "BaseConfig 插件“react”中的错误在 - ERROR in Plugin "react" was conflicted between 部署 React 应用程序时出错,它一直在说 &lt;&lt; Plugin "react" was conflicted between "package.json » eslint-config-react-app » &gt;&gt; - Error when deploying react app and it keeps sayings << Plugin "react" was conflicted between "package.json » eslint-config-react-app » >> 插件“react”在“package.json”之间发生冲突 - Plugin "react" was conflicted between "package.json 插件“react”在“package.json » eslint-config-react-app 之间发生冲突 - Plugin "react" was conflicted between "package.json » eslint-config-react-app 创建反应应用程序错误 - Create-react-app error 错误:无法加载在“.eslintrc”中声明的解析器“babel-eslint”:在 create-react-app 中找不到模块“babel-eslint” - Error: Failed to load parser 'babel-eslint' declared in '.eslintrc': Cannot find module 'babel-eslint' in create-react-app ESLint:插件“反应”在两者之间发生冲突 - ESLint: Plugin "react" was conflicted between 使用 create-react-app 命令反应错误 - React error with create-react-app command create-react-app完整性错误窗口 - create-react-app eintegrity error windows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM