简体   繁体   English

eslint 'html-webpack-plugin' 应该列在项目的依赖中,而不是 devDependencies 中。 (导入/无外部依赖项)

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

相关问题 eslint 应该列在项目的依赖项中,而不是 devDependencies - eslint should be listed in the project's dependencies, not devDependencies eslint import / no-extraneous-dependencies无法解决依赖关系 - eslint import/no-extraneous-dependencies fails to resolve the depencency 'prop-types' 应该列在项目的依赖项中,而不是 devDependencies - 'prop-types' should be listed in the project's dependencies, not devDependencies eslintrc 中的 ESLint 配置无效:- 意外的顶级属性“import/no-extraneous-dependencies” - ESLint configuration in .eslintrc is invalid: - Unexpected top-level property “import/no-extraneous-dependencies” 无法将我的商店文件导入App.js错误:“商店”应列在项目的依赖项中 - Cannot import my store file into App.js error: 'store' should be listed in the project's dependencies 你把Babel和Webpack放在devDependencies或Dependencies中吗? - Do you put Babel and Webpack in devDependencies or Dependencies? html-webpack-plugin和webpack 2:无起始斜杠“ /” - html-webpack-plugin and webpack 2: no starting slash '/' 使用 html-webpack-plugin 配置 webpack - webpack configuration using html-webpack-plugin 解决HTML-webpack-plugin中样式表的路径 - Resolve path for stylesheets in HTML-webpack-plugin 是否应该将 refs 列为 useEffect 等的依赖项? - Should refs be in listed as dependencies for useEffect and such?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM