天天看點

Error: clean-webpack-plugin only accepts an options object.Error: clean-webpack-plugin only accepts an options object.源碼

Error: clean-webpack-plugin only accepts an options object.

最近在學習Webpack,在plugins 中調用clean-webpack-plugin 的時候報錯,

譯:https://github.com/johnagan/clean-webpack-plugin

轉:https://stackoverflow.com/questions/55190450/clean-webpack-plugin-only-accepts-an-options-object

源碼

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:'Hello, kankan.'
        })
    ],
    output:{
        filename:'[name].bundle.js',
        path: path.resolve(__dirname,'dist')
    },

};
           

Error

Error: clean-webpack-plugin only accepts an options object. See:
            https://github.com/johnagan/clean-webpack-plugin#options-and-defaults-optional
    at new CleanWebpackPlugin 
           

Solution

CleanWebpackPlugin 不需要參數

可以嘗試下面的文法,

new CleanWebpackPlugin()
           

對于錯誤,要認真看所用的插件版本,自學習的時候可能是用的最新代碼庫和插件,在運作教程或者教材上面的指令的時候要慎重,有些新的插件函數或者庫有所改動,導緻一些文法和指令産生了變化,以至于編譯出錯.

學習也是一個思考的過程,思考蘊含的原理。

幾個有趣的案例:

怦然心動表白畫軸:https://blog.csdn.net/qq_38025939/article/details/89365800

陰陽月曆:https://blog.csdn.net/qq_38025939/article/details/89351585

個人首頁:https://kankan.fun

明天的一定會感謝現在拼命的自己!