[英]eslint 'html-webpack-plugin' should be listed in the project's dependencies, not devDependencies. (import/no-extraneous-dependencies)
In my Vs code editor, i am getting following error in simple require statement like:在我的 Vs 代码编辑器中,我在简单的 require 语句中收到以下错误,例如:
const HtmlWebpackPlugin = require('html-webpack-plugin')
Error: [eslint] 'html-webpack-plugin' should be listed in the project's dependencies, not devDependencies.错误: [eslint] 'html-webpack-plugin' 应该列在项目的依赖项中,而不是 devDependencies。 (import/no-extraneous-dependencies) (导入/无外部依赖项)
Can anyone explain what is no-extraneous-dependencies and why it is giving me this error in simple require statement in my webpack config.谁能解释什么是无外部依赖关系以及为什么它在我的 webpack 配置中的简单 require 语句中给我这个错误。 I went through this link: eslint should be listed in the project's dependencies, not devDependencies but it was not much helpful as it did not explain why i am adding that line.我浏览了这个链接: eslint 应该列在项目的依赖项中,而不是 devDependencies但它没有太大帮助,因为它没有解释我为什么要添加该行。
My eslintrc.json file:我的 eslintrc.json 文件:
{
"env": {
"browser": true,
"es6": true,
"commonjs": true,
"node": true
},
"extends": ["airbnb", "prettier", "prettier/react"],
"plugins": ["prettier"],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
}
}
You just need to tell eslint that it's ok to require dev dependency in webpack. 你只需要告诉eslint可以在webpack中要求dev依赖。
You can create .eslintrc
in your webpack folder with 您可以在webpack文件夹中创建.eslintrc
rules:
import/no-extraneous-dependencies: [error, { devDependencies: true }]
This will prevent the error from appearing. 这样可以防止出现错误。
Alternatively you can just set 或者你可以设置
const HtmlWebpackPlugin = require('html-webpack-plugin'); // eslint-disable-line import/no-extraneous-dependencies
to disable only this line 仅禁用此行
In your .eslintrc.json
include webpack.config.js
in devDependencies
:在您的.eslintrc.json
中devDependencies
webpack.config.js
"rules": {
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": [
"**/*.test.ts?(x)",
"**/*.spec.ts?(x)",
"**/test-utils.ts",
"webpack.config.js"
]
}
],
Add "type": "module"
to your package.json
, then you can use ES6 import without this error/warning.将"type": "module"
添加到您的package.json
,然后您可以使用 ES6 导入而不会出现此错误/警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.