Webpack-dev-server: TypeError: Cannot read property 'compile' of undefined

Created on 5 Mar 2018  路  9Comments  路  Source: webpack/webpack-dev-server

  • Operating System: Windows 10 1709
  • Node Version: v8.9.4
  • NPM Version: 5.6.0
  • webpack Version: 3.3.0
  • webpack-dev-server Version: 3.1.0
  • [x] This is a bug
  • [ ] This is a modification request

Code

I don't have a webpack config, as I am using the webpacker gem for Ruby on Rails. I am using a default configuration with the ERB loader.

This

Expected Behavior

I expect to be able to run the webpack-dev-server.

Actual Behavior

When attempting to run the webpack-dev-server, an error is being thrown:

./bin/webpack-dev-server

$ C:\Users\jonas\projects\apps\nativegap\node_modules\webpack-dev-server\bin\webpack-dev-server.js:405
    throw e;
    ^

TypeError: Cannot read property 'compile' of undefined
    at addCompilerHooks (C:\Users\jonas\projects\apps\nativegap\node_modules\webpack-dev-server\lib\Server.js:71:16)
    at new Server (C:\Users\jonas\projects\apps\nativegap\node_modules\webpack-dev-server\lib\Server.js:81:5)
    at startDevServer (C:\Users\jonas\projects\apps\nativegap\node_modules\webpack-dev-server\bin\webpack-dev-server.js:398:14)
    at processOptions (C:\Users\jonas\projects\apps\nativegap\node_modules\webpack-dev-server\bin\webpack-dev-server.js:361:5)
    at Object.<anonymous> (C:\Users\jonas\projects\apps\nativegap\node_modules\webpack-dev-server\bin\webpack-dev-server.js:504:1)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)

Note that I am using this package with the webpacker gem for Ruby on Rails. However, the same happens when running webpack-dev-server.

Most helpful comment

webpack-dev-server 3.x is only compatible with webpack 4.x, as the peer dependencies already warn you about.

All 9 comments

webpack-dev-server 3.x is only compatible with webpack 4.x, as the peer dependencies already warn you about.

I am facing the same error.

@aruprakshit I was able to fix it by downgrading webpack-dev-server to 2.x

Downgrading webpack-dev-server to 3.0.0 works fine.

1 - Upgrade webpack to v4, you must change the webpack.config.js file for compatibility. or
2 - Downgrade webpack-dev-server to exactly v3.0.0 as @Nufeen said.

Hey I am facing with the same problem too

@byamasu-patrick for me it was solved by installing webpack-dev-server. I guess it was included in webpack before.

Kind of sketch because when I downgrade npm gives a notification that there is a high severity vulnerability

npm WARN [email protected] requires a peer of webpack@^4.0.0-beta.1 but none is installed. You must install peer dependencies yourself.

added 910 packages from 590 contributors and audited 9040 packages in 16.697s
found 1 high severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details

Downgrading version does fix this with vue-cli

Locking to 3.0.0 worked for me:
"webpack-dev-server": "3.0.0"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tulika21-zz picture tulika21-zz  路  3Comments

uMaxmaxmaximus picture uMaxmaxmaximus  路  3Comments

piotrszaredko picture piotrszaredko  路  3Comments

gimmi picture gimmi  路  3Comments

MJ111 picture MJ111  路  3Comments