Search code examples
ruby-on-railswebpackerbwebpackerenoent

Module build failed: Error: spawn bin/rails ENOENT


After adding the ERB loader and adding the .erb file extension to my application pack (with webpacker), I am getting the following error:

ERROR in ./app/webpack/packs/application.js.erb
Module build failed: Error: spawn bin/rails ENOENT
    at _errnoException (util.js:1024:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
    at onErrorNT (internal/child_process.js:372:16)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
 @ multi (webpack)-dev-server/client?http://localhost:3035 ./app/webpack/packs/application.js.erb

it is also happening with the sample hello_erb.js.erb pack.

Here is an example app that reproduces the problem: https://github.com/jonhue/test_app


Solution

  • The ERB runner configuration contains a setting that must be changed for it to work on Windows. Open config\webpack\loaders\erb.js and replace this line:

    runner: "bin/rails runner"
    

    with this line:

    runner: "ruby bin\\rails runner