johnagan / clean-webpack-plugin

A webpack plugin to remove your build folder(s) before building

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot use 'new' with an expression whose type lacks a call or construct signature.

muuvmuuv opened this issue · comments

Issue description or question

Updated my packages and node and now getting this error:

Cannot use 'new' with an expression whose type lacks a call or construct signature.

Webpack Config

import { platform, userInfo } from 'os'
import { resolve } from 'path'
import chalk from 'chalk'
import { Configuration, BannerPlugin } from 'webpack'
import TerserPlugin from 'terser-webpack-plugin'
import CleanPlugin from 'clean-webpack-plugin'
import WebpackBuildNotifierPlugin from 'webpack-build-notifier'
import pkg from './package.json'

const Banner = `${'┄'.repeat(46)}
${pkg.displayName} (${pkg.name})
${pkg.description}

@version ${pkg.version}
@license ${pkg.license}
@author ${pkg.author.name} (${pkg.author.url})
@readme ${pkg.homepage}
@pkg ${pkg.repository}
${'┄'.repeat(46)}`

export default (_, argv: Configuration): Configuration => {
  const platformName = platform()
  const developerName = userInfo().username
  const mode = argv.mode ? argv.mode : 'none'
  const isProd = mode === 'production'
  const isDev = mode === 'development'

  // Show general information
  console.log('whoIsMe:', chalk.whiteBright(developerName))
  console.log('whichOs:', chalk.whiteBright(platformName))
  console.log('devMode:', isDev ? chalk.green('true') : chalk.red('false'), '\n')

  return {
    target: 'node',
    entry: resolve(__dirname, 'src', 'extension.ts'),
    output: {
      path: resolve(__dirname, 'dist'),
      filename: 'extension.js',
      libraryTarget: 'commonjs2',
      devtoolModuleFilenameTemplate: '../[resource-path]',
    },
    devtool: isDev ? 'cheap-module-source-map' : 'source-map',
    externals: {
      // the vscode-module is created on-the-fly and must be excluded.
      // See: https://webpack.js.org/configuration/externals/
      vscode: 'commonjs vscode',
    },
    resolve: {
      extensions: ['.ts', '.js'],
    },
    optimization: {
      namedModules: true,
      namedChunks: true,
      minimize: isProd,
      minimizer: [new TerserPlugin()],
    },
    plugins: [
      new WebpackBuildNotifierPlugin({
        title: 'Sundial',
        logo: resolve(__dirname, 'assets', 'icon.jpg'),
      }),
      new CleanPlugin({
        cleanOnceBeforeBuildPatterns: ['dist'],
      }),
      new BannerPlugin(Banner),
    ],
    module: {
      rules: [
        {
          test: /\.ts$/,
          exclude: /node_modules/,
          use: [
            {
              loader: 'ts-loader',
            },
          ],
        },
      ],
    },
  }
}

Environment

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

  System:
    OS: macOS 10.14.5
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 61.57 MB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 12.1.0 - ~/.nvm/versions/node/v12.1.0/bin/node
    npm: 6.9.0 - ~/.nvm/versions/node/v12.1.0/bin/npm
  npmPackages:
    clean-webpack-plugin: ^3.0.0 => 3.0.0 
    webpack: ^4.34.0 => 4.34.0 

As noted in the release notes for v3.0.0, you'll need to change to a named export. In your case:

import { CleanWebpackPlugin as CleanPlugin } from 'clean-webpack-plugin'

Also, as of v2 this plugin will by default clean your webpack's output.path directory without any additional configuration.

You can replace:

      new CleanPlugin({
        cleanOnceBeforeBuildPatterns: ['dist'],
      }),

with:

      new CleanPlugin(),