TypeError: CleanwebpackPlugin is not a constructor

前端 未结 10 2049
感动是毒
感动是毒 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 09:05

    I am not very much familiar with webpack and currently learning it

    although this thing below helped me fix the issue

    I just uninstall clean-webpack-plugin and then reinstall as dependency before this i've intalled as a dev-dependency

    after uninstall and installing it like that : npm install --save clean-webpack-plugin

    and by adding this

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

    solved my issue!!

    hope it helps

    0 讨论(0)
  • 2021-01-01 09:06

    I had the same issue today, right now. As you can tell, there was a mismatch between the docs and the actual code. And in fact, you can see in the last commit they merged both to the documentation:

    and also to the code:

    So I just switched from const CleanWebpackPlugin = require('clean-webpack-plugin') to

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

    and it works fine.

    I think you may have been caught in between things. Reinstall the npm package and try again, it should work.

    I wrote a bit of what you can see in their public repository because very often when sudden changes like this happen, you'll find your own answer in the repo, probably in the last commits. And it's good reading a bit of the code you use, especially if it helps you troubleshoot your issue :)

    0 讨论(0)
  • 2021-01-01 09:06

    Looks like docs are broken, correct code is

    const CleanWebpackPlugin = require('clean-webpack-plugin')

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

    With the update you'll need to do the following to include it

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

    Then in the array of plugins replace add the following

    plugins: [
         new CleanWebpackPlugin(['dist]),
    ]
    

    with

    plugins: [
         new CleanWebpackPlugin(),
    ]
    

    As the with the update there is no need to pass any parameters as it will remove all files inside webpack's output.path directory, as well as all unused webpack assets after every successful rebuild.

    0 讨论(0)
提交回复
热议问题