TypeError: CleanwebpackPlugin is not a constructor

前端 未结 10 2048
感动是毒
感动是毒 2021-01-01 08:39

i\'m trying to preview a vue web application through webpack-server-dev.I\'m following this guide https://medium.com/the-web-tub/creating-your-first-vue-js-pwa-project-22f7

相关标签:
10条回答
  • 2021-01-01 08:41

    I had the same problem, and I solved it in the following way:

    
        const { CleanWebpackPlugin } = require('clean-webpack-plugin');
    
    
    
        plugins: [
            new CleanWebpackPlugin({
                cleanAfterEveryBuildPatterns: ['dist']
            })
        ]
    
    
    0 讨论(0)
  • 2021-01-01 08:41

    I had the same issue today, I figured out that I also had to remove webpack.config.js file.

    After deleting the file, i had to rerun npm install

    -> Application started successfully.

    --

    Inside webpack.config.js some old references were placed.

    0 讨论(0)
  • 2021-01-01 08:43

    For those finding this error with the recent updates to nativescript-vue, I fixed it by changing webpack.config.js (top level file in app folder). As above, it now reflects the syntax in the CleanWebpackPlugin docs.

    //const CleanWebpackPlugin = require("clean-webpack-plugin");
      const { CleanWebpackPlugin } = require('clean-webpack-plugin');
    

    and

    //new CleanWebpackPlugin(itemsToClean, { verbose: !!verbose }),
      new CleanWebpackPlugin(),
    
    0 讨论(0)
  • 2021-01-01 08:46

    The correct one is to use this import:

    const { CleanWebpackPlugin } = require('clean-webpack-plugin');
    

    And then instead of passing an array with the distribution folder, change it to

    plugins: [
         new CleanWebpackPlugin(),
         //...
    ]
    
    0 讨论(0)
  • 2021-01-01 08:53

    This is probably a weird outlier reason for this - but I just came across this while setting up an old project on a new linux machine. It turned out I didn't have dev dependencies installed for my project (by default if npm config is set to production it won't install dev dependencies when running npm install - although I'm not sure exactly why mine was set to production), my webpack cli is 4 but my project is at 2.6.1 so it was using the webpack 4 but my webpack.config was for 2. So make sure your dev dependencies are installed.

    0 讨论(0)
  • 2021-01-01 08:54

    CleanWebpackPlugin v3.0.0

    Replaced default export with named export CleanWebpackPlugin

    [https://github.com/johnagan/clean-webpack-plugin/releases/tag/v3.0.0]

    correct code is:

    // es modules
    import { CleanWebpackPlugin } from 'clean-webpack-plugin';
    
    // common js
    const { CleanWebpackPlugin } = require('clean-webpack-plugin');
    
    0 讨论(0)
提交回复
热议问题