js-dxtools / webpack-validator

Validates your webpack config with Joi
MIT License
295 stars 29 forks source link

webpack.optimize.OccurenceOrderPlugin is not a constructor Error #155

Closed outsideris closed 7 years ago

outsideris commented 7 years ago

When I run npm test, I encountered following error.

webpack-validator/test/passing-configs/angular2-webpack-starter.development.js:73
  plugins: [new webpack.optimize.OccurenceOrderPlugin(true), new webpack.optimize.CommonsChunkPlugin({ name: 'polyfills', filename: 'polyfills.bundle.js', minChunks: Infinity }),
            ^

TypeError: webpack.optimize.OccurenceOrderPlugin is not a constructor
    at Object.<anonymous> (angular2-webpack-starter.development.js:73:5)
    at Module._compile (module.js:570:32)
    at loader (/Users/outsider/Dropbox/projects/github/webpack-validator/node_modules/babel-register/lib/node.js:126:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/outsider/Dropbox/projects/github/webpack-validator/node_modules/babel-register/lib/node.js:136:7)
    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 filePathToConfigObj (index.js:6:16)
    at Array.map (native)
    at Object.<anonymous> (index.js:20:3)
    at Module._compile (module.js:570:32)
    at loader (/Users/outsider/Dropbox/projects/github/webpack-validator/node_modules/babel-register/lib/node.js:126:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/outsider/Dropbox/projects/github/webpack-validator/node_modules/babel-register/lib/node.js:136:7)
    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 Object.<anonymous> (index.test.js:2:1)
    at Module._compile (module.js:570:32)
    at loader (/Users/outsider/Dropbox/projects/github/webpack-validator/node_modules/babel-register/lib/node.js:126:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/outsider/Dropbox/projects/github/webpack-validator/node_modules/babel-register/lib/node.js:136:7)
    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 /Users/outsider/Dropbox/projects/github/webpack-validator/node_modules/mocha/lib/mocha.js:219:27
    at Array.forEach (native)
    at Mocha.loadFiles (/Users/outsider/Dropbox/projects/github/webpack-validator/node_modules/mocha/lib/mocha.js:216:14)
    at Mocha.run (/Users/outsider/Dropbox/projects/github/webpack-validator/node_modules/mocha/lib/mocha.js:468:10)
    at Object.<anonymous> (/Users/outsider/Dropbox/projects/github/webpack-validator/node_modules/mocha/bin/_mocha:403:18)
    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.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
npm ERR! Test failed.  See above for more details.

As I dig the reason, I guess it caused because OccurenceOrderPlugin has been renamed to OccurrenceOrderPlugin. See https://github.com/webpack/webpack/issues/1964 . All tests are passed when I change OccurenceOrderPlugin to OccurrenceOrderPlugin in the test.

However, I'm not sure it is a common problem or just for me.

outsideris commented 7 years ago

In my pull request, the same error is occurred. If you confirmed, I could fix it.

kentcdodds commented 7 years ago

If you're using Webpack 2, then please uninstall webpack-validator and close this issue. See the note in the README about webpack 2 not being supported (it has its own validation built-in :tada:)

simeyla commented 7 years ago

As said above OccurenceOrderPlugin is renamed to OccurrenceOrderPlugin (spelling mistake)

However it was not mentioned that it is now enabled by default - so you can just remove the line

    new webpack.optimize.OccurenceOrderPlugin(),
xubeng commented 6 years ago

@simeyla It does not work. Then output: WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.