Webpack优化构造函数未找到

时间:2017-04-13 15:50:53

标签: javascript node.js webpack webpack-dev-server webpack-plugin

我正在测试windows dev系统上的webpack和node.js。 我有这个脚本' webpack.config.js'

var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');

module.exports = {
  context: __dirname,
  devtool: debug ? "inline-sourcemap" : null,
  entry: "./js/scripts.js",
  output: {
    path: __dirname + "/js",
    filename: "scripts.min.js"
  },
  plugins: debug ? [] : [
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
  ],
};

当我使用生产标签调用webpack时,我收到以下错误:

C:\Users\srussell\Desktop\GitHub\nodejsTest\webpack.config.js:14
    new webpack.optimize.OccurenceOrderPlugin(),
    ^

TypeError: webpack.optimize.OccurenceOrderPlugin is not a constructor
    at Object.<anonymous> (C:\Users\srussell\Desktop\GitHub\nodejsTest\webpack.config.js:14:5)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at requireConfig (C:\Users\srussell\AppData\Roaming\npm\node_modules\webpack\bin\convert-argv.js:96:18)
    at C:\Users\srussell\AppData\Roaming\npm\node_modules\webpack\bin\convert-argv.js:109:17

然而,当我从cmd中的节点控制台运行console.log(require('webpack'));时,它显示我已安装webpack并且可以使用优化功能和方法。

C:\Users\srussell\Desktop\GitHub\nodejsTest>node
> console.log(require('webpack'));
{ [Function: webpack]
  WebpackOptionsDefaulter: [Function: WebpackOptionsDefaulter],
  WebpackOptionsApply: [Function: WebpackOptionsApply],
  Compiler: { [Function: Compiler] Watching: [Function: Watching] },
  MultiCompiler: [Function: MultiCompiler],
  NodeEnvironmentPlugin: [Function: NodeEnvironmentPlugin],
  validate: [Function: bound validateSchema],
  validateSchema: [Function: validateSchema],
  WebpackOptionsValidationError: [Function: WebpackOptionsValidationError],
  DefinePlugin: [Getter],
  NormalModuleReplacementPlugin: [Getter],
  ContextReplacementPlugin: [Getter],
  IgnorePlugin: [Getter],
  WatchIgnorePlugin: [Getter],
  BannerPlugin: [Getter],
  PrefetchPlugin: [Getter],
  AutomaticPrefetchPlugin: [Getter],
  ProvidePlugin: [Getter],
  HotModuleReplacementPlugin: [Getter],
  SourceMapDevToolPlugin: [Getter],
  EvalSourceMapDevToolPlugin: [Getter],
  EvalDevToolModulePlugin: [Getter],
  CachePlugin: [Getter],
  ExtendedAPIPlugin: [Getter],
  ExternalsPlugin: [Getter],
  JsonpTemplatePlugin: [Getter],
  LibraryTemplatePlugin: [Getter],
  LoaderTargetPlugin: [Getter],
  MemoryOutputFileSystem: [Getter],
  ProgressPlugin: [Getter],
  SetVarMainTemplatePlugin: [Getter],
  UmdMainTemplatePlugin: [Getter],
  NoErrorsPlugin: [Getter],
  NoEmitOnErrorsPlugin: [Getter],
  NewWatchingPlugin: [Getter],
  EnvironmentPlugin: [Getter],
  DllPlugin: [Getter],
  DllReferencePlugin: [Getter],
  LoaderOptionsPlugin: [Getter],
  NamedModulesPlugin: [Getter],
  HashedModuleIdsPlugin: [Getter],
  ModuleFilenameHelpers: [Getter],
  optimize:
   { AggressiveMergingPlugin: [Getter],
     AggressiveSplittingPlugin: [Getter],
     CommonsChunkPlugin: [Getter],
     ChunkModuleIdRangePlugin: [Getter],
     DedupePlugin: [Getter],
     LimitChunkCountPlugin: [Getter],
     MinChunkSizePlugin: [Getter],
     OccurrenceOrderPlugin: [Getter],
     UglifyJsPlugin: [Getter] },
  dependencies: {} }
undefined 

任何帮助表示赞赏!如果它有帮助,这是项目的链接。 https://github.com/russellsean/nodejsTest

2 个答案:

答案 0 :(得分:2)

愚蠢的我...发生了两个'r'字母,我最初有一个。

答案 1 :(得分:2)

OccurenceOrderPlugin已重命名为OccurrenceOrderPlugin,其中包含两个 r