webpacker: Cannot read property 'compile' of undefined when running ./bin/webpack-dev-server

ruby 2.3.4 rails 5.1.4 node 8.9.4

I get next error when trying to run ./bin/webpack-dev-server

/home/project/node_modules/webpack-dev-server/bin/webpack-dev-server.js:405
    throw e;
    ^

TypeError: Cannot read property 'compile' of undefined
    at addCompilerHooks (/home/project/node_modules/webpack-dev-server/lib/Server.js:71:16)
    at new Server (/home/project/node_modules/webpack-dev-server/lib/Server.js:81:5)
    at startDevServer (/home/project/node_modules/webpack-dev-server/bin/webpack-dev-server.js:398:14)
    at processOptions (/home/project/node_modules/webpack-dev-server/bin/webpack-dev-server.js:361:5)
    at Object.<anonymous> /home/project/node_modules/webpack-dev-server/bin/webpack-dev-server.js:504:1)
    at Module._compile (module.js:662:30)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)
    at Function.Module._load (module.js:507:3)

Does anyone faced with the same error?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 13
  • Comments: 29 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I was having the same issue with: Ruby: 2.4.1 Rails: 5.1.2 Node: 8.9.4

I was following the Readme instructions to upgrade(yarn upgrade webpack-dev-server --latest), however this installed webpack-dev-server v3.1.0. When I downgraded to v2.11.1 (yarn upgrade webpack-dev-server@^2.11.1) my dev server worked again!

I can confirm. Sticking with 2.11.1 works for the interim.

use webpack-dev-server@2.9.1 version npm i webpack-dev-server@2.9.1 --save dev when terminal shows npm audit fix then do not use this otherwise npm will install latest webpack-dev-server

Reverting back to version 2.9.1 still shows the security hole:

# Run  npm install --save-dev webpack-dev-server@3.1.14  to resolve 1 vulnerability
SEMVER WARNING: Recommended action is a potentially breaking change
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Missing Origin Validation                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ webpack-dev-server                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ webpack-dev-server [dev]                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ webpack-dev-server                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/725                       │
└───────────────┴──────────────────────────────────────────────────────────────┘

The problem with downgrading is that there’s a CVE for webpack-dev-server < 3.11.1 - https://nvd.nist.gov/vuln/detail/CVE-2018-14732

Operating System: Windows Node Version: 8.9.4 NPM Version: 6.5.0 webpack Version: 3.6.0 webpack-dev-server Version: 2.9.0

i’m having the same problem of cannot destructure property compile of 'undefined' or 'null' and my solution is at https://github.com/webpack/webpack-dev-server/issues/1259 @smackgg

with this command: npm install --save-dev webpack-dev-server@2.9.7

Thanks everyone. We will update Webpacker to use webpack 4.0 soon - in meantime please use the supported dev server version.

I experienced the same. Thank you for this solution.

Yep downgrading to 2.11.1 works. Rails 5.1.5

I confirm that @Terit solution works!

It seems like there should be some version ranges specified going to ease confusion. I’d be more than happy to help with implementation.

My proposal is to

  • change documentation - Depending on webpack version, you may not be able to use webpack-dev-sever@latest.
  • maybe have a check / warning to help new folks figure out what is going on when the specified versions don’t work together.

Happy to help out, and I know that there is a shift to webpack 4 where this won’t be an issue soon, but that’s not to say there won’t be the same issue in the future.

I met the same issue, and downgrading webpack-dev-server to 2.11.1 fixed it. Thanks!

I’m seeing the same thing with:

Ruby: 2.5.0 Rails: 5.2.0.rc1 Node: v8.9.4