webpack错误记录(不定期更新)

前端 同时被 2 个专栏收录
5 篇文章 0 订阅
9 篇文章 0 订阅

CleanWebpackPlugin相关

CleanWebpackPlugin is not a constructor

更新记录
date: 2020-12-31 初始化错误记录

代码

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

  module.exports = {
    entry: {
      app: './src/index.js',
      print: './src/print.js'
    },
    plugins: [
     new CleanWebpackPlugin(['dist']),
      new HtmlWebpackPlugin({
        title: 'Output Management'
      })
    ],
    output: {
      filename: '[name].bundle.js',
      path: path.resolve(__dirname, 'dist')
    }
  };

错误信息

[webpack-cli] Failed to load 'D:\workplace\前端\learnWebpack\demo1\webpack.config.js'
[webpack-cli] Error: clean-webpack-plugin only accepts an options object. See:
            https://github.com/johnagan/clean-webpack-plugin#options-and-defaults-optional
    at new CleanWebpackPlugin (D:\workplace\前端\learnWebpack\demo1\node_modules\clean-webpack-plugin\dist\clean-webpack-plugin.js:27:13)

版本信息

  • webpack 5.11.1
  • webpack-cli 4.3.0
  • CleanWebpackPlugin 3.0.0

错误原因
新版本插件语法发生变化,不要在函数里面传递参数就行

 new CleanWebpackPlugin()

参考资料
https://www.jianshu.com/p/0e99366ce796

webpack.config.js

Automatic publicPath is not supported in this browser

修改记录
date: 2020-12-31 初始化记录

问题描述
使用html-loader处理html文件中的图片引入,webpack执行报错

ERROR in   Error: D:\workplace\前端\learnWebpack\packageImg\src\index.html:97
  /******/  if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");
                            ^
  Error: Automatic publicPath is not supported in this browser

解决方法
webpack,config.js文件中配置 output.publicPath

    output:{
        filename:'built.js',
        path:resolve(__dirname,'build'),
        publicPath:'./'
    },

参考文件
https://blog.csdn.net/xzlAwin/article/details/109098593

  • 1
    点赞
  • 0
    评论
  • 1
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 猿与汪的秘密 设计师:白松林 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值