首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到Webpack优化构造函数

找不到Webpack优化构造函数
EN

Stack Overflow用户
提问于 2017-04-13 23:50:53
回答 2查看 6.8K关注 0票数 4

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

代码语言:javascript
复制
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时,我收到了以下错误:

代码语言:javascript
复制
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,并且可以使用优化函数和方法。

代码语言:javascript
复制
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

EN

回答 2

Stack Overflow用户

发布于 2018-05-10 01:31:12

OccurenceOrderPlugin已重命名为OccurrenceOrderPlugin with two r

票数 3
EN

Stack Overflow用户

发布于 2017-04-14 00:00:34

我太傻了。事件有两个'r‘字母,我最初只有一个。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43396702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档