Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails erb loader Compile Error #1529

Closed
andybluey opened this issue May 27, 2018 · 7 comments
Closed

Rails erb loader Compile Error #1529

andybluey opened this issue May 27, 2018 · 7 comments

Comments

@andybluey
Copy link

andybluey commented May 27, 2018

Hi All,

I've just included webpacker (inc erb support) to an existing project. I've moved code from the asset pipeline to the example in the docs 'hello_erb.js.erb'.

I can get console.log('<%= image_tag "logo.svg" %>');

but not
<% helpers = ActionView::Helpers::JavaScriptHelper %> $('.class').html('<%= helpers.escape_javascript(@query) %>');

With the error:
"Failed to compile.
./app/javascript/packs/hello_erb.js.erb
Module build failed: Error: rails-erb-loader failed with code: 1
at ChildProcess. (/Users.../node_modules/rails-erb-loader/index.js:120:16)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:877:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
@ multi (webpack)-dev-server/client?http://localhost:3035 ./app/javascript/packs/hello_erb.js.erb"

The error message isn't making it terribly easy to search further.

I've also tried digging through some previous issues that might be related https://github.com/rails/webpacker/issues/1256#issuecomment-367573638 and trying some different loader settings and file headings with no luck.

Let me know if you need anymore info.

Thanks

webpacker '3.5'
rails '5.1.2'

@vill
Copy link

vill commented May 28, 2018

I think the details should be looked for here.

If you are using Spring, then you can run DISABLE_SPRING=1 ./bin/webpack-dev-server or run rails console first, then exit the console and try running the webpacker as you previously ran it.

@andybluey
Copy link
Author

Hi Vill,

Thanks for getting back to me!

Sorry, just to confirm, should DISABLE_SPRING=1 ./bin/webpack-dev-server be included in the loader file - or run via console?

I did try both ways and also tried the rails console method but still getting the same error.

Thanks,
Andy

@vill
Copy link

vill commented May 28, 2018

@andybluey, I think the issue is with rails-erb-loader. Possible solutions to the issue are taken from the comment and the issue.

@Neilos
Copy link

Neilos commented May 28, 2018

I ran into this issue (i.e. same error message) after running rails webpacker:install:erb.

rails-erb-loader does have an issue with poor error messages (see here), which is certainly an obstacle to solving issues like this one, but, if you see this error message, the underlying issue may not be rails-erb-loader itself.

First, check the syntax in your erb files for potential compilation issues. Remember that the file is interpreted by erb before the file is interpreted as javascript.

I'm using version 3.4.3 of webpacker, and the cause of this issue for me was that webpacker's example erb file hello_erb.js.erb was not erb compilable.

The problem was in the javascript comment at the top of the file:

// Run this example by adding <%= javascript_pack_tag 'hello_erb' %> to the head of your layout file

This has now been corrected in later versions of webpacker (and version 3.5 which is what @andybluey is using) to:

// Run this example by adding <%%= javascript_pack_tag 'hello_erb' %> to the head of your layout file

Note the double %%.
I manually made this correction and it fixed the issue for me.

Although, my compilation issue and @andybluey 's issue aren't the same, I'm posting here, in case anyone else seeing the same message has similar compilation related problems.

@luislezcair
Copy link

I'm facing the same problem. erb-loader fails when there's a call to an asset helper like asset_pack_path. I've been struggling with this issue here.

@joshleblanc
Copy link
Contributor

Just going to drop this here since it confounded me.

I was getting this error because the erb loader that webpacker:install:erb creates, has the following runner:

runner: (/^win/.test(process.platform) ? 'ruby ' : '') + 'bin/rails runner'

In my case, this was running a different version of ruby than I had set up for my rails project. Rails was expecting 2.4.5, and my system ruby was 2.5.

Changing the line to specify the correct ruby install fixed the problem

runner: (/^win/.test(process.platform) ? 'C:/Ruby24-x64/bin/ruby ' : '') + 'bin/rails runner'

rokumatsumoto added a commit to rokumatsumoto/boyutluseyler that referenced this issue Dec 9, 2019
- Remove pagy.js.erb file who initiates Pagy on JS
- Enable Spring when using webpacker:compile command on travis.yml file

From eb-activity.log file
---
ERROR in ./app/javascript/packs/hello_erb.js.erb
Module build failed (from ./node_modules/rails-erb-loader/index.js):
Error: rails-erb-loader failed with code: 1
    at ChildProcess.<anonymous> (/var/app/ondeck/node_modules/rails-erb-loader/index.js:128:16)
    at ChildProcess.emit (events.js:193:13)
    at maybeClose (internal/child_process.js:999:16)
    at Socket.stream.socket.on (internal/child_process.js:403:11)
    at Socket.emit (events.js:193:13)
    at Pipe._handle.close (net.js:614:12)

ERROR in ./app/javascript/lib/pagy.js.erb
Module build failed (from ./node_modules/rails-erb-loader/index.js):
Error: rails-erb-loader failed with code: 1
    at ChildProcess.<anonymous> (/var/app/ondeck/node_modules/rails-erb-loader/index.js:128:16)
    at ChildProcess.emit (events.js:193:13)
    at maybeClose (internal/child_process.js:999:16)
    at Socket.stream.socket.on (internal/child_process.js:403:11)
    at Socket.emit (events.js:193:13)
    at Pipe._handle.close (net.js:614:12)

usabilityhub/rails-erb-loader#63
rails/webpacker#1560
rails/webpacker#1529
@guillaumebriday
Copy link
Member

Is this issue still relevant ?

Feel free to close it if not 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants