gpt4 book ai didi

javascript - ESLint 错误 - ESLint 找不到配置 "react-app"

转载 作者:行者123 更新时间:2023-12-03 07:17:33 25 4
gpt4 key购买 nike

我和我的团队,使用 create-react-app 引导命令启动一个新的 React 项目。
我们在项目中添加了 eslint 部分,但我们遇到了以前从未发现过的恼人错误。
当我们启动命令时

 yarn run lint

这里的错误:
enter image description here

这里是 package.json:
{
"name": "name of the app",
"version": "0.1.0",
"private": true,
"dependencies": {
"jwt-decode": "^2.2.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-intl": "^3.12.0",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react-scripts": "3.3.0",
"redux": "^4.0.5",
"redux-saga": "^1.1.3",
"reselect": "^4.0.0",
"styled-components": "^5.0.1"
},
"scripts": {
"analyze": "react-app-rewired build",
"build": "react-scripts build",
"cypress": "./node_modules/.bin/cypress open",
"eject": "react-scripts eject",
"lint:write": "eslint --debug src/ --fix",
"lint": "eslint --debug src/",
"prettier": "prettier --write src/*.tsx src/*.ts src/**/*.tsx src/**/*.ts src/**/**/*.tsx src/**/**/*.ts src/**/**/**/*.tsx src/**/**/**/*.ts src/**/**/**/**/*.tsx src/**/**/**/**/*.ts",
"start": "react-scripts start",
"storybook": "start-storybook -p 6006 -c .storybook",
"test": "react-scripts test",
"upgrade:check": "npm-check",
"upgrade:interactive": "npm-check --update"
},
"eslintConfig": {
"extends": "react-app"
},
"lint-staged": {
"*.(ts|tsx)": [
"yarn run prettier"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@cypress/webpack-preprocessor": "^4.1.2",
"@storybook/addon-actions": "^5.3.12",
"@storybook/addon-info": "^5.3.12",
"@storybook/addon-knobs": "^5.3.12",
"@storybook/addon-links": "^5.3.12",
"@storybook/addons": "^5.3.12",
"@storybook/preset-create-react-app": "^1.5.2",
"@storybook/react": "^5.3.12",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/jest": "^24.0.0",
"@types/jwt-decode": "^2.2.1",
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"@types/react-redux": "^7.1.7",
"@types/react-router": "^5.1.4",
"@types/react-router-dom": "^5.1.3",
"@types/storybook__addon-knobs": "^5.2.1",
"@types/styled-components": "^4.4.2",
"cypress": "^4.0.1",
"eslint": "^6.8.0",
"husky": "^4.2.1",
"lint-staged": "^10.0.7",
"npm-check": "^5.9.0",
"prettier": "^1.19.1",
"react-app-rewire-webpack-bundle-analyzer": "^1.1.0",
"react-app-rewired": "^2.1.5",
"react-docgen-typescript-webpack-plugin": "^1.1.0",
"redux-devtools-extension": "^2.13.8",
"storybook-addon-jsx": "^7.1.14",
"ts-loader": "^6.2.1",
"typescript": "~3.7.2",
"webpack": "^4.41.6",
"webpack-bundle-analyzer": "^3.6.0"
}
}

我们还尝试添加创建一个 .eslintrc 文件并添加
{
"extends": "react-app"
}

但什么都没有改变。

最佳答案

react-scripts应该已经包含 ESLint 和 eslint-config-react-app节点依赖项中的 ESLint 配置(参见 docs )。

You don’t need to install it separately in Create React App projects.


如果 ESLint 无法找到 react-app config,可能有冲突或重复的 ESLint 配置依赖项安装在 react-scripts 之外(即另一个 eslint-config-react-app 安装)。您可以使用 npm ls [package] 进行检查命令(即 npm ls eslint-config-react-app )。
解决此问题的最佳方法可能是从 package.json 中删除这些包。允许像 eslint-config-react-app 这样的配置在 react-scripts按预期使用(基于 comment)。如果之后问题仍然存在,请尝试删除 node_modules文件夹和 package-lock.json然后再次重新安装依赖项可能会起作用。否则,升级到更新的 npm版本可能会有所不同。
老答案:
您的 package.json可能缺少对等依赖 eslint-config-react-app其中包括 eslint 预设 react-app .您需要按照说明在此处安装 https://www.npmjs.com/package/eslint-config-react-app .
注意:即使这是 create-react-app将其捆绑为 react-scripts , 你的 lint脚本无法访问 react-app .
"eslintConfig": {
"extends": "react-app"
}
关于 .eslintrc ,您的 package.json 中已经有了 ESLint 的配置。所以你应该可以安全地删除 .eslintrc .

关于javascript - ESLint 错误 - ESLint 找不到配置 "react-app",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60431931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com