Webpack-dev-server: Webpack 4 support with MultiCompiler

Created on 5 Feb 2018  路  12Comments  路  Source: webpack/webpack-dev-server

  • Operating System: macOS 10.13.2
  • Node Version: v8.9.3
  • Yarn Version: 1.3.2
  • webpack Version: 4.0.0-beta.0
  • webpack-dev-server Version: same error with both 3.0.0-alpha6 and 2.11.1
  • [x] This is a bug
  • [ ] This is a modification request

Code

const webpack = require('webpack');
const path = require('path');
const WebpackDevServer = require('webpack-dev-server');

const configs = [
    {
        mode: 'production',
        entry: {
            foo: require.resolve('./foo.js')
        },
        output: {
            filename: '[name].js',
            path: path.resolve(__dirname, './public')
        },
    }
]

const compiler = webpack(configs);
const devServer = new WebpackDevServer(compiler, {
    publicPath: '/public/'
});

devServer.listen(9999, 'localhost', err => {
    if (err) {
        return console.log(err);
    }
});

foo.js

console.log('foo');

Expected Behavior

Should start the dev server

Actual Behavior

Throws the below error

/Users/robrichard/projects/dibs-scripts/node_modules/tapable/lib/Tapable.js:63
        throw new Error(`Plugin could not be registered at '${name}'. Hook was not found.\n` +
        ^

Error: Plugin could not be registered at 'compile'. Hook was not found.
BREAKING CHANGE: There need to exist a hook at 'this.hooks'. To create a compatiblity layer for this hook, hook into 'this._pluginCompat'.
    at MultiCompiler.plugin (/Users/robrichard/projects/dibs-scripts/node_modules/tapable/lib/Tapable.js:63:9)
    at MultiCompiler.deprecated [as plugin] (internal/util.js:52:15)
    at plugins (/Users/robrichard/projects/dibs-scripts/node_modules/webpack-dev-server/lib/plugins.js:53:12)
    at new DevServer (/Users/robrichard/projects/dibs-scripts/node_modules/webpack-dev-server/lib/DevServer.js:61:5)
    at Object.<anonymous> (/Users/robrichard/projects/dibs-scripts/webpack.js:19:19)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

For Bugs; How can we reproduce the behavior?

Run the script posted above

Most helpful comment

@sokra Is there anything we can do? Now that webpack@4 is out of the door, this will block so many upgrades. @TheLarkInn If you have any idea on how to solve it, I'm happy to help.

All 12 comments

@sokra how should we tackled MultiCompiler for wds hooks. 馃

Have the same issue :(

@sokra Is there anything we can do? Now that webpack@4 is out of the door, this will block so many upgrades. @TheLarkInn If you have any idea on how to solve it, I'm happy to help.

Same issue here

by changing line 69 of lib/Server.js to the following The build works again for MultiCompiler:

compiler.compilers.forEach((comp) => {
    comp.plugin('compile', invalidPlugin);
    comp.plugin('invalid', invalidPlugin);
    comp.plugin('done', (stats) => {
      this._sendStats(this.sockets, stats.toJson(clientStats));
      this._stats = stats;
    });
  });

I think the approach to handling deprecated plugin vs. hooks needs to be updated on webpack side. However, it would be nice if wds could switch to hooks of webpack > 4?

I published [email protected] with experimental support for MultiCompiler. Please test it and report if it works correctly. I would like at least 2-3 reports because I have never used MultiCompiler myself 馃槃.

Thanks for the hint @janhommes.

Hey @SpaceK33z! It works on my side. I cannot fully test it, because some plugins are still failing, but we don鈥檛 get this error anymore! 馃憤

Works for me @SpaceK33z,
No problems with project 1 of 4, had to use the patch from (https://medium.com/webpack/webpack-4-released-today-6cdb994702d4
==> yarn add html-webpack-plugin@webpack-contrib/html-webpack-plugin

馃憤

Hey @SpaceK33z,
3 different projects work fine on my end.

Thanks

馃憤馃憤馃憤

@SpaceK33z works for me as well. Thanks for the fast fix!

Thanks for testing everyone! I will publish the release tonight.

[email protected] has been published with the fix.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

movie4 picture movie4  路  3Comments

daryn-k picture daryn-k  路  3Comments

Ky6uk picture Ky6uk  路  3Comments

MJ111 picture MJ111  路  3Comments

eyakcn picture eyakcn  路  3Comments