webpack HtmlWebpackPlugin不是构造函数吗?

问题描述

package.json

   {
      "name": "test2","version": "1.0.0","description": "","main": "webpack.config.js","scripts": {
        "test": "echo \"Error: no test specified\" && exit 1","build": "webpack"
      },"author": "","license": "ISC","devDependencies": {
        "html-webpack-plugin": "^4.5.0","webpack": "^5.1.3","webpack-cli": "^4.1.0"
      }
    }

webpack.config.js

const {resolve} = require('path');
const {HtmlWebpackPlugin} = require('html-webpack-plugin');

module.exports = {
    entry: './src/index.js',output: {
        filename: 'built.js',path: resolve(__dirname,'build')
    },plugins: [
        new HtmlWebpackPlugin({template: './src/webpack.html'})
    ],mode: 'development'
};

我的错误:

[webpack-cli] TypeError: HtmlWebpackPlugin is not a constructor
    at Object.<anonymous> (D:\webpack workspace\test2\webpack.config.js:16:9)
    at Module._compile (D:\webpack workspace\test2\node_modules\v8-compile-cache\v8-compile-cache.js:194:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (D:\webpack workspace\test2\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
    at requireConfig (D:\webpack workspace\test2\node_modules\webpack-cli\lib\groups\ConfigGroup.js:73:18)
    at Array.map (<anonymous>)

我很好奇为什么错误消息“ HtmlWebpackPlugin不是构造函数!”为什么?
我很好奇为什么错误消息“ HtmlWebpackPlugin不是构造函数!”为什么?
我很好奇为什么错误消息“ HtmlWebpackPlugin不是构造函数!”为什么?

解决方法

不是这样吗?

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...