webpack-dev-server not working with Webpack 4+

Info:

"webpack": "^4.4.1",
 "webpack-cli": "^2.0.13",
"webpack-dev-server": "^2.11.2"

Node: v8.10.0
Npm: 5.6.0

Config:

devServer: {
           contentBase: path.join(__dirname, "dist/app"),
           index: 'index.html',
           compress: true,
           port: 9000,
           allowedHosts: [
               'https://fonts.googleapis.com'
           ]
       },

What is the current behavior?
After running npm script webpack-dev-server --port 3000
I getting this:

> webpack-dev-server --port 3000

module.js:549
    throw err;
    ^

Error: Cannot find module 'webpack/bin/config-yargs'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (************\node_modules\webpack-dev-server\bin\webpack-dev-server.js:54:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

What is the expected behavior?
Must work, damn it 🙂

Author: Fantashit

1 thought on “webpack-dev-server not working with Webpack 4+

  1. Not sure if this issue was resolved for you @FlamesoFF but I had the same problem. I’ve got webpack 4.6.0 and after reinstalling webpack-cli 2.0.15 it worked. Maybe uninstalling the package and reinstalling would do it for you.

Comments are closed.