[英]I am having a conflict error between eslint configuation and base configuration when running a react project in development
I am trying to run a react project in development but I got the following error:我正在尝试在开发中运行一个反应项目,但出现以下错误:
Plugin "react" was conflicted between "../.eslintrc.json" and "BaseConfig » /home/crudengr/Documents/projects/***/***/web-app/node_modules/eslint-config-react-app/base.js".
The above error did not allow the page to load.上述错误不允许页面加载。 I noticed that whenever I save any js file I get this error but whenever I save in package.json file the error disappears and the page loads successful.
我注意到,每当我保存任何 js 文件时,我都会收到此错误,但每当我保存在 package.json 文件中时,错误就会消失并且页面加载成功。
.eslintrc.json file .eslintrc.json文件
{
"parserOptions": {
"ecmaVersion": 8,
"requireConfigFile": false,
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true,
"spread": true
},
"sourceType": "module",
"babelOptions": {
"presets": ["@babel/preset-react"]
}
},
"env": {
"browser": true,
"node": true,
"jquery": true,
"es6": true,
"jest": true
},
"plugins": [
"react",
"jsx-a11y"
],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:prettier/recommended",
"prettier"
],
"globals": {
"describe" :true,
"context" :true,
"before" :true,
"beforeEach" :true,
"after" :true,
"afterEach" :true,
"it" :true,
"expect" :true,
"workbox" :true,
"importScripts" :true
},
"parser": "@babel/eslint-parser",
"rules": {
"no-fallthrough": "error",
"no-unreachable": "error",
"no-cond-assign": "error",
"valid-typeof": "error",
"no-func-assign": "error",
"no-extra-semi": "error",
"linebreak-style": [
"error",
"UNIX"
],
"no-unused-vars": "error",
"no-console": "off",
"no-undef": "error",
"no-empty": "error",
"no-case-declarations": "error",
"no-mixed-spaces-and-tabs": "error",
"no-useless-escape": "error",
"prettier/prettier": "error",
"react/jsx-no-undef": "error",
"react/jsx-no-bind": [
"error",
{
"allowArrowFunctions": true,
"allowBind": false,
"ignoreRefs": false
}
],
"react/no-children-prop": "error",
"react/no-deprecated": "error",
"react/boolean-prop-naming": "error",
"react/no-is-mounted": "error",
"react/no-find-dom-node": "error",
"react/no-did-update-set-state": "error",
"react/no-unknown-property": "error",
"react/no-unused-prop-types": "error",
"react/jsx-no-duplicate-props": "error",
"react/no-unused-state": "error",
"react/jsx-uses-vars": "error",
"react/prop-types": "error",
"react/react-in-jsx-scope": "error",
"react/no-string-refs": "error",
"jsx-a11y/href-no-hash": [
0
],
"react/no-unescaped-entities": "error",
"react/display-name": "error",
"react/jsx-pascal-case": "error",
"array-callback-return": "error",
"no-loop-func": "error",
"jsx-a11y/anchor-is-valid": "error",
"prefer-const": [
"error",
{
"destructuring": "any",
"ignoreReadBeforeAssign": false
}
],
"no-var": "error"
},
"settings": {
"react": {
"version": "16.5"
}
}
}
/node_modules/eslint-config-react-app/base.js file /node_modules/eslint-config-react-app/base.js文件
'use strict';
module.exports = {
root: true,
parser: '@babel/eslint-parser',
plugins: ['react'],
env: {
browser: true,
commonjs: true,
es6: true,
jest: true,
node: true,
},
parserOptions: {
sourceType: 'module',
requireConfigFile: false,
babelOptions: {
presets: [require.resolve('babel-preset-react-app/prod')],
},
},
settings: {
react: {
version: 'detect',
},
},
rules: {
'react/jsx-uses-vars': 'warn',
'react/jsx-uses-react': 'warn',
},
};
In my package json file:在我的 package json 文件中:
"devDependencies": {
"@babel/eslint-parser": "^7.16.5",
"@babel/plugin-transform-react-jsx": "^7.16.7",
"@babel/preset-react": "^7.16.7",
"babel-jest": "^27.4.5",
"dotenv-webpack": "^7.0.3",
"eslint": "^8.6.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.28.0",
"jest": "^27.4.5",
"ts-jest": "^27.1.2"
}
node version: 17 npm version: 8 OS type: Ubuntu Linux节点版本:17 npm 版本:8 操作系统类型:Ubuntu Linux
Any fix for the above error will be appreciated.对上述错误的任何修复将不胜感激。 Thanks.
谢谢。
Rename your folder "Documents" to "documents".将您的文件夹“文档”重命名为“文档”。
Because create-react-app is pulling in the react eslint plugin, you shouldn't need it in your package.json config.因为 create-react-app 正在引入 react eslint 插件,所以在 package.json 配置中不需要它。 Try removing it.
尝试删除它。
Keep names of all the directories (including your react-app directory) in all lowercase.保持所有目录的名称(包括您的 react-app 目录)全部小写。 Hopefully it will solve your problem.
希望它能解决你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.