Webpack 2: TypeError: _webpack2.default.optimize.OccurenceOrderPlugin is not a function

I’m using webpack with an express server and the webpack-hot-middleware, while I’m getting following error on starting:

> babel-node server

/Users/Glenn/Projects/react-boilerplate/webpack.config.js:28
  plugins: [new _webpack2.default.optimize.OccurenceOrderPlugin(), new _webpack2.default.HotModuleReplacementPlugin(), new _webpack2.default.NoErrorsPlugin()]
            ^

TypeError: _webpack2.default.optimize.OccurenceOrderPlugin is not a function
    at Object.<anonymous> (webpack.config.js:24:5)
    at Module._compile (module.js:413:34)
    at loader (/Users/Glenn/Projects/react-boilerplate/node_modules/babel-register/lib/node.js:130:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/Glenn/Projects/react-boilerplate/node_modules/babel-register/lib/node.js:140:7)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/Users/Glenn/Projects/react-boilerplate/server.js:23:17)
    at Module._compile (module.js:413:34)

npm ERR! Darwin 15.3.0
npm ERR! argv "/usr/local/Cellar/node/5.5.0/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v5.5.0
npm ERR! npm  v3.5.3
npm ERR! code ELIFECYCLE
npm ERR! react-boilerplate@1.0.0 start: `babel-node server`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the react-boilerplate@1.0.0 start script 'babel-node server'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the react-boilerplate package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     babel-node server
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs react-boilerplate
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls react-boilerplate
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/Glenn/Projects/react-boilerplate/npm-debug.log

I’m using babel-node as I am using ES6 imports/exports on my server configuration.

The plugins in the webpack config looks like this:

...
  plugins: [
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  ]
...

Any clues?

Author: Fantashit

5 thoughts on “Webpack 2: TypeError: _webpack2.default.optimize.OccurenceOrderPlugin is not a function

  1. Current setup for Webpack 2.

    var debug = process.env.NODE_ENV !== “production”;
    var webpack = require(‘webpack’);

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

    Why? Because this tutorial is on Webpack 1. We just need to tweak slightly to make it work with Webpack 2.
    Changes

    1. debug ? “inline-sourcemap” : false, <– used to be null
    2. removed dedupe plugin – it’s no longer needed.

Comments are closed.