gpt4 book ai didi

reactjs - 为什么我在运行 ESLint 时得到 "Definition for rule ' import/no-extraneous-dependencies' was not found”?

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

我正在使用 React 开发 Electron 应用程序,并且正在使用 Typescript、Webpack、Babel 和 ESLint。出于某种原因,我进入了我的 main.js 文件,这是我的捆绑文件,以下行:

try {
// Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
// eslint-disable-next-line import/no-extraneous-dependencies
const supportsColor = __webpack_require__(/*! supports-color */ "./node_modules/supports-color/index.js");

if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
exports.colors = [
当我运行 npm run lint 时会触发以下错误:
> biomech@1.0.0 lint
> eslint .


/Users/lucas_sg/Documents/pf-biomech/dist/main.js
2946:2 error Definition for rule 'import/no-extraneous-dependencies' was not found import/no-extraneous-dependencies

✖ 1 problem (1 error, 0 warnings)

npm ERR! code 1
npm ERR! path /Users/lucas_sg/Documents/pf-biomech
npm ERR! command failed
npm ERR! command sh -c eslint .

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/lucas_sg/.npm/_logs/2021-01-29T22_56_39_247Z-debug.log
当我查看日志时,我不觉得我知道更多关于如何调试错误的信息:
0 verbose cli [
0 verbose cli '/usr/local/Cellar/node/15.6.0/bin/node',
0 verbose cli '/usr/local/bin/npm',
0 verbose cli 'run',
0 verbose cli 'lint'
0 verbose cli ]
1 info using npm@7.4.0
2 info using node@v15.6.0
3 timing config:load:defaults Completed in 2ms
4 timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 1ms
5 timing config:load:builtin Completed in 1ms
6 timing config:load:cli Completed in 2ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:/Users/lucas_sg/Documents/pf-biomech/.npmrc Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:/Users/lucas_sg/.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:/usr/local/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:setUserAgent Completed in 0ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 8ms
19 verbose npm-session 3273db6630b48789
20 timing npm:load Completed in 16ms
21 timing command:run-script Completed in 1117ms
22 verbose stack Error: command failed
22 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/index.js:64:27)
22 verbose stack at ChildProcess.emit (node:events:379:20)
22 verbose stack at maybeClose (node:internal/child_process:1065:16)
22 verbose stack at Process.ChildProcess._handle.onexit (node:internal/child_process:296:5)
23 verbose pkgid biomech@1.0.0
24 verbose cwd /Users/lucas_sg/Documents/pf-biomech
25 verbose Darwin 20.2.0
26 verbose argv "/usr/local/Cellar/node/15.6.0/bin/node" "/usr/local/bin/npm" "run" "lint"
27 verbose node v15.6.0
28 verbose npm v7.4.0
29 error code 1
30 error path /Users/lucas_sg/Documents/pf-biomech
31 error command failed
32 error command sh -c eslint .
33 verbose exit 1
我的 .eslintrc 文件是:
{
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
}
}
还有我的 包.json 如果它有用:
{
"name": "Electron app",
"version": "1.0.0",
"description": "",
"main": "./dist/main.js",
"preload": "./dist/preload.js",
"scripts": {
"dev": "concurrently --success first \"npm run dev:electron\" \"npm run dev:react\" -k",
"dev:electron": "NODE_ENV=development webpack --config webpack.electron.config.js --mode development && electron .",
"dev:react": "NODE_ENV=development webpack serve --config webpack.react.config.js --mode development",
"build:electron": "NODE_ENV=production webpack --config webpack.electron.config.js --mode production",
"build:react": "NODE_ENV=production webpack --config webpack.react.config.js --mode production",
"build": "npm run build:electron && npm run build:react",
"pack": "electron-builder --dir",
"dist": "electron-builder",
"lint": "eslint .",
"format": "prettier --write \"**/*.+(js|jsx|json|yml|yaml|css|md|vue)\""
},
"keywords": [],
"license": "MIT",
"build": {
"files": [
"dist/",
"node_modules/",
"package.json"
],
"productName": "Biomech",
"appId": "com.example.app",
"directories": {
"output": "dist"
}
},
"devDependencies": {
"@babel/preset-env": "^7.9.5",
"@babel/preset-react": "^7.9.4",
"@babel/preset-typescript": "^7.9.0",
"@types/electron-devtools-installer": "^2.2.0",
"@types/react-router-dom": "^5.1.7",
"@types/regenerator-runtime": "^0.13.0",
"dpdm": "^3.6.0",
"electron": "^11.2.1",
"electron-builder": "^22.7.0",
"electron-devtools-installer": "^3.1.1",
"eslint": "^7.18.0",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^4.5.1",
"husky": "^4.3.8",
"lint-staged": "^10.5.3",
"prettier": "^2.2.1",
"react-router-dom": "^5.2.0",
"webpack": "^5.11.1",
"webpack-cli": "^4.3.1",
"webpack-dev-server": "^3.11.1"
},
"dependencies": {
"@babel/core": "^7.12.10",
"@popperjs/core": "^2.6.0",
"@types/node": "^14.14.22",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"axios": "^0.21.1",
"babel-loader": "^8.2.2",
"bootstrap": "^4.5.3",
"chokidar": "^3.5.1",
"core-js": "^3.8.3",
"css-loader": "^5.0.1",
"electron-fetch": "^1.7.3",
"fsevents": "^2.3.1",
"ini": "^2.0.0",
"jquery": "^3.5.1",
"react": "^17.0.1",
"react-bootstrap": "^1.4.0",
"react-dom": "^17.0.1",
"react-google-login": "^5.2.2",
"style-loader": "^2.0.0"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint && npm run format"
}
},
"lint-staged": {
"*.+(js|jsx)": "eslint --fix",
"*.+(json|css|md)": "prettier --write"
}
}
我不知道 eslint-disable-next-line import/no-extraneous-dependencies在哪里线来自。如果它来自 Webpack、Babel 或其他东西。但我认为我实际上并不需要它,因为我什至从未输入过有关无关依赖项的规则。我尝试将空规则添加到 .eslintrc 只是为了至少有意义,但我找不到任何关于 的信息无外部依赖 在 ESLint 文档中,所以我永远无法添加它。

最佳答案

eslint .命令也将对所有文件(包括捆绑的脚本文件)运行 linting。您应该添加 .eslintignore文件并忽略您希望运行 lint 的文件。
在您的情况下,请忽略添加 **/*.js告诉 eslint 忽略掉毛 .js文件。

关于reactjs - 为什么我在运行 ESLint 时得到 "Definition for rule ' import/no-extraneous-dependencies' was not found”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65963363/

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