question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack dev server with rails-erb-loader and spring hangs

See original GitHub issue

This was originally posted at webpacker https://github.com/rails/webpacker/issues/785.

Using rails-erb-loader@^5.2.1 and webpacker gem 3.0.1, rails 5.1.4 and spring 2.0.2.

I’ve the problem that in my current project, webpack-dev-server hangs when first started:

→   ./bin/webpack-dev-server
 11% building modules 10/10 modules 0 active
Project is running at http://localhost:3035/
webpack output is served from /packs/
Content not from webpack is served from/Users/.../public/packs
404s will fallback to /index.html
 66% building modules 468/469 modules 1 active ...xternal_application_form/index.js.erb

It sometimes hangs at some other point, eg.:

 67% building modules 479/480 modules 1 active ..._custom_question_answers_form.vue.erb

so the hang is not consistent, but it always displays some .erb at the end of output.

If I cancel the dev server and restart it, it goes through without a problem:

→   ./bin/webpack-dev-server
 11% building modules 10/10 modules 0 active                                                                                                                                                                    Project is running at http://localhost:3035/
webpack output is served from /packs/
Content not from webpack is served from /Users/.../public/packs                                                                                                                           404s will fallback to /index.html
Hash: 6b8d3991aafe09cef922                                                                                                                                                                                      Version: webpack 3.5.6
Time: 8058ms
[...]

I noticed that it happens only when spring was not started before. If spring is started already (e.g. because of a rails console), the compilation goes through on first try without the need to cancel it first.

Additionally, when I disable spring by commenting out the spring loader from bin/rails, or by using DISABLE_SPRING=1 ./bin/webpack-dev-server it always goes through without a problem, too. So I suspect it to be the combination of spring and the rails erb loader that makes it hang somehow (or is anything else calling bin/rails during compiling?)

I tried to set a timeout for rails-erb-loader by editing node_modules/rails-erb-loader/index.js, suspecting a hang while compiling the erb assets, but this did not change anything (still hangs).

How can we debug this further to see where exactly it hangs and why?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:9
  • Comments:20

github_iconTop GitHub Comments

14reactions
PikachuEXEcommented, Nov 9, 2018

I do this with 5.5.0:

/* put this in file like /config/webpack/loaders/erb.js */
/* global process:false */

module.exports = {
  test:     /\.erb$/,
  enforce:  "pre",
  exclude:  /node_modules/,

  use: [{
    loader:   "rails-erb-loader",
    options:  {
      runner:     (/^win/.test(process.platform) ? "ruby " : "") + "bin/rails runner",
      env:        {
        ...process.env,
        DISABLE_SPRING: 1,
      },
    },
  }],
}

Edit 1: Add missing quote Edit 2: Add file path

0reactions
PikachuEXEcommented, Sep 14, 2020

Sorry just added the example to README Let me know if anything else can be done for this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack dev server with rails-erb-loader and spring hangs
Using rails-erb-loader@^5.2.1 and webpacker gem 3.0.1, rails 5.1.4 and spring 2.0.2. I've the problem that in my current project, ...
Read more >
Webpack builds successfully, but hangs without exiting
I use the same webpack config in dev and production. In dev, it's configured to watch for file changes and restart the server....
Read more >
Webpacker stuck on Compiling... : r/rails - Reddit
UPDATE: This seems to be caused by a memory leak within webpack-dev-server. For me, the lock happens once the webpacker service container ...
Read more >
Using Webpack with Spring Boot | Bootify.io
This includes Webpack with Bootstrap or Tailwind CSS for the frontend, so you get the whole following configuration including DevServer and ...
Read more >
When using react.js webpack-dev-server does not bundle
When using react.js, do you run webpack-dev-server and find that when you change your files, webpack-dev-server does not automatically rebundle your project ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found