最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - eslint 'html-webpack-plugin' should be listed in the project's dependencies, not devDepende

programmeradmin1浏览0评论

In my Vs code editor, i am getting following error in simple require statement like:

const HtmlWebpackPlugin = require('html-webpack-plugin')

Error: [eslint] 'html-webpack-plugin' should be listed in the project's dependencies, not 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. 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.

My eslintrc.json file:

{
  "env": {
    "browser": true,
    "es6": true,
    "commonjs": true,
    "node": true
  },
  "extends": ["airbnb", "prettier", "prettier/react"],
  "plugins": ["prettier"],
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  }
}

In my Vs code editor, i am getting following error in simple require statement like:

const HtmlWebpackPlugin = require('html-webpack-plugin')

Error: [eslint] 'html-webpack-plugin' should be listed in the project's dependencies, not 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. 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.

My eslintrc.json file:

{
  "env": {
    "browser": true,
    "es6": true,
    "commonjs": true,
    "node": true
  },
  "extends": ["airbnb", "prettier", "prettier/react"],
  "plugins": ["prettier"],
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  }
}
Share Improve this question asked May 19, 2018 at 4:04 rosnkrosnk 1,0982 gold badges15 silver badges38 bronze badges 0
Add a comment  | 

3 Answers 3

Reset to default 16

You just need to tell eslint that it's ok to require dev dependency in webpack.

You can create .eslintrc in your webpack folder with

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:

"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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论