Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: CleanWebpackPlugin is not a constructor #143

Closed
ghost opened this issue May 25, 2019 · 5 comments
Closed

TypeError: CleanWebpackPlugin is not a constructor #143

ghost opened this issue May 25, 2019 · 5 comments

Comments

@ghost
Copy link

ghost commented May 25, 2019

Issue description or question

In the docs is wrong the way get the plugin variable, it's distructuring the module unnecessarily:

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

Doing that way, triggers this error:

TypeError: CleanWebpackPlugin is not a constructor

The right is:

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

Webpack Config

const path = require('path');

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

module.exports = {
    mode: 'development',
    entry: {
        newtab: './src/newtab.js'
    },
    output: {
        filename: '[name].js',
        path: path.resolve(__dirname, 'dist')
    },
    plugins: [
        new CleanWebpackPlugin(),
    ],
};

Environment

Run: npx envinfo --system --binaries --npmPackages clean-webpack-plugin,webpack

  System:
    OS: Windows 10
    CPU: (4) x64 Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
    Memory: 3.67 GB / 7.88 GB
  Binaries:
    Node: 10.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.13.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD

Please, test the things before put in the docs and test the installation of module before publish it to Github because it can confuse the users, thanks!

@gustawdaniel
Copy link

gustawdaniel commented May 28, 2019

I have the same error.

To fix use

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

instead of

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

so docs is broken.

I see that this was changed 6 days ago in d0e3408 and described in #114

Last release v2.0.2 is from 22 days ago · 20 commits to master since this release

So everything clear. In official Readme is described how to install next (not released) version, but it is breaking change so in my opinion it should not be merged into master but in branch dev or versioned branch.

Anyway: if you have this error now use

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

for last released version v2.0.2

@gustawdaniel
Copy link

gustawdaniel commented May 28, 2019

Other solution is change default displayed branch from master to lts or last stable release or something like this because of many end users see README.md on main page as source of knowledge about last released version.

@bigbossx
Copy link

@gustawdaniel it's right
const CleanWebpackPlugin = require('clean-webpack-plugin');

@chrisblossom
Copy link
Collaborator

It is normal for a github project's readme to be out of date with what is published on npm. Either use github tags or view the readme from the npm page.

Repository owner locked as resolved and limited conversation to collaborators May 29, 2019
@johnagan
Copy link
Owner

johnagan commented May 30, 2019

released fixed in v3.0.0

UnHumbleBen referenced this issue in Colt/webpack-demo-app Jul 1, 2019
- Added html-loader to automatically require the files we reference in img tags
- Added file-loader to handle the svg,png,jpg,gif files from our images
- Configured file-loader to add our images to an imgs directory in dist
- Also configured it to add a hash to their filenames
- Lastly, added clean-webpack-plugin to our production config to clean out the dist directory each time we build
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants