简体   繁体   English

在开发中运行反应项目时,我在 eslint 配置和基本配置之间遇到冲突错误

[英]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.

相关问题 WebStorm 中的 ESLint 配置错误(React 项目) - ESLint configuration error at WebStorm (React project) 请帮忙,当我尝试在我的 React 项目中安装材料 UI 时遇到问题 - Kindly help,am having issues when I try to install material UI in my react project create-react-app 的开发服务器遇到 ESLINT 检测到的错误时停止自动刷新 - Development server of create-react-app stops auto refresh when meeting an error detected by ESLINT 保存我的代码时 Eslint 配置错误 - Eslint configuration error when saving my code 我在浏览器中检索我的反应项目时遇到问题 - I am having trouble retrieving my react project in the browser React Project ESlint 错误“意外的令牌导出” - React Project ESlint error "Unexpected Token Export" 为什么在运行 ESLint 时出现“未找到规则‘导入/无无关依赖’的定义”? - Why am I getting "Definition for rule 'import/no-extraneous-dependencies' was not found" when running ESLint? 为什么我在系统中第一次运行 react js 项目时收到此错误消息? - Why I am getting this error message when I run react js project first time in my system? 运行创建的 React Native 项目时出错 - Error when running created React Native project 我正在为后端使用 Sanity CMS 构建 React 应用程序,但在向后端发送数据时遇到客户端错误 - I am building a React Application using the Sanity CMS for the backend but I am running into a client error when sending data to the backend
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM