rails 5.1 Webpack-dev server starting error
Asked Answered
M

4

7
ruby version - 2.4.2

rails - 5.1

rails new my_app --webpack=react 

when I try to start server with foreman start -f Procfile.dev or just ./bin/webpack-dev-server

I get following error and could not find the cause of it. Any help is appreciated.

    /Users/shani/Wspace/myapp/node_modules/webpack-dev-server/bin/webpack-dev-server.js:405
    throw e;
    ^

TypeError: Cannot read property 'compile' of undefined
    at addCompilerHooks (/Users/shani/Wspace/myapp/node_modules/webpack-dev-server/lib/Server.js:71:16)
    at new Server (/Users/shani/Wspace/myapp/node_modules/webpack-dev-server/lib/Server.js:81:5)
    at startDevServer (/Users/shani/Wspace/myapp/node_modules/webpack-dev-server/bin/webpack-dev-server.js:398:14)
    at processOptions (/Users/shani/Wspace/myapp/node_modules/webpack-dev-server/bin/webpack-dev-server.js:361:5)
    at Object.<anonymous> (/Users/shani/Wspace/myapp/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)
Murtagh answered 1/3, 2018 at 10:48 Comment(0)
R
3

I was having exact same exception with webpack-dev-server v3.1.0. I downgraded to v2.11.1 and all is good.

https://github.com/rails/webpacker/issues/1303#issuecomment-369090507

Ribaldry answered 1/3, 2018 at 23:3 Comment(0)
M
1

I had the same error with webpack-dev-server v3.1.0. Downgrading to v2.11.2 resolved the issue for me.

Minnieminnnie answered 1/3, 2018 at 22:59 Comment(0)
Z
1

Go to config/webpack/environment.js You need to change the code of the webpack config to ".prepend"

Should look something like this:

const { environment } = require('@rails/webpacker')

// Bootstrap 3 has a dependency over jQuery:
const webpack = require('webpack')
environment.plugins.**prepend**('Provide',
  new webpack.ProvidePlugin({
    $: 'jquery',
    jQuery: 'jquery'
  })
)

module.exports = environment
Zolner answered 31/3, 2018 at 12:1 Comment(0)
O
0

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

Downgrade to v2.11.2 (as recommended above).

Oglethorpe answered 19/7, 2018 at 14:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.