简体   繁体   English

webpack-cli TypeError: webpack.optimize.CommonsChunkPlugin 不是构造函数

[英]webpack-cli TypeError: webpack.optimize.CommonsChunkPlugin is not a constructor

Hope everybody is having a good weekend so far.希望到目前为止,每个人都度过了一个愉快的周末。

So i retrieve this error when running: webpack --config webpack.dev.js所以我在运行时检索到这个错误: webpack --config webpack.dev.js

This happened after I updated NVM NPM and Webpack.这发生在我更新 NVM NPM 和 Webpack 之后。 Running Windows 10.运行 Windows 10。

I already tried all of the stackoverflow solutions but nothing seems to work for me unfortunately.我已经尝试了所有的 stackoverflow 解决方案,但不幸的是,似乎没有什么对我有用。

This is my webpack.common.js这是我的 webpack.common.js


const path = require('path');
var webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
//const extractCSS = new ExtractTextPlugin('[name].[chunkhash].css')
const extractCSS  = new ExtractTextPlugin({
  filename: '[name].[chunkhash].css',
  allChunks: true
});

module.exports = {
  entry: {
    app: ['./src/js/app.js'],
    //vendor: ['bootstrap', 'jquery', 'socket.io-client', './src/js/jquery.tablesorter.min.js', 'purecloud-platform-client-v2'],
    vendor: ['bootstrap', 'jquery', 'socket.io-client', './src/js/jquery.tablesorter.min.js'],
    'styles-custom': __dirname + '/src/js/styles-custom.js',
    'styles-vendor': __dirname + '/src/js/styles-vendor.js'
  },
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '',
    filename: '[name].[chunkhash].js'
  },
  node: {
    fs: 'empty',
    tls: 'empty'
  },
  module: {
    rules: [{
      test: /\.css$/i,
      use: extractCSS.extract({
        use: {
          loader: 'css-loader',
          options: {
            minimize: true
          }
        }
      })
    },
    {
      test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
      loader: 'file-loader',
      options: {
        name: '[name].[hash].[ext]',
        publicPath: '',
        outputPath: 'assets/'
      }  
    }]
  },
  plugins: [   
    new CleanWebpackPlugin(['dist']),
    new webpack.optimize.CommonsChunkPlugin({
      names: ['vendor']
    }),
    new webpack.ProvidePlugin({
      $: "jquery",
      jQuery: "jquery",
      "window.jQuery": "jquery"
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true,
      debug: false,
      options: {
        context: __dirname
      }
    }),
    new HtmlWebpackPlugin({
      filename: './index.html',
      template: './src/assets/index.template.html'
    }),
    extractCSS
  ]
} 

Does anybody know how I can fix this?有人知道我该如何解决这个问题吗? Thanks in advance提前致谢

It's because webpack.optimize.CommonsChunkPlugin it was removed on webpack v4.这是因为webpack.optimize.CommonsChunkPlugin在 webpack v4 上被删除。 So probably, when you updated the webpack version you lost this.因此,当您更新 webpack 版本时,您可能会丢失它。

CommonChunkPlugin it's now splitChunks configuration inside optimization node. CommonChunkPlugin 现在是优化节点内的 splitChunks 配置。

See optimization.splitChunks请参阅optimization.splitChunks

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM