rails-erb-loader: Error: rails-erb-loader failed with code: 1
Running the following:
ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/swathishah/shopify-app/bin/spring rails --trace assets:precompile
But I randomly get following error:
ERROR in ./app/javascript/components/layout_tab.js.erb
Module build failed: Error: rails-erb-loader failed with code: 1
at ChildProcess.<anonymous> (/Users/swathishah/shopify-app/node_modules/rails-erb-loader/index.js:108:16)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:886:16)
at Socket.<anonymous> (internal/child_process.js:342:11)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at Pipe._handle.close [as _onclose] (net.js:501:12)
@ ./app/javascript/components/tabs.js 12:0-44
@ ./app/javascript/packs/notifications_react.jsx
Package.json has following:
{
"name": "shopify-app",
"private": true,
"dependencies": {
"@rails/webpacker": "^3.2.1",
....
"rails-erb-loader": "^5.4.1",
...
"yarn": "^1.3.2"
},
"devDependencies": {
"webpack-dev-server": "^2.11.1"
}
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 9
- Comments: 81 (1 by maintainers)
Links to this issue
Commits related to this issue
- Remove rails-erb-loader which causing to fail on AWS EC2 - Remove pagy.js.erb file who initiates Pagy on JS - Enable Spring when using webpacker:compile command on travis.yml file From eb-activity.l... — committed to rokumatsumoto/boyutluseyler by rokumatsumoto 5 years ago
- Hack to fix missing quill icons The icons for the Quill toolbar have to be overwritten manually as, prior to this change, all that was rendered was the path for each of the SVG files. Am currently us... — committed to kohrVid/kohrVid-website by kohrVid 4 years ago
We had a similar problem with
erb-loaderon CircleCI. Everything worked fine locally but failed to build on CircleCi.I sshed into CI job and ran
$ cat app/javascript/vendor/javascripts/smart_listing/smart_listing.coffee.erb | bin/rails runner ./node_modules/rails-erb-loader/erb_transformer.rb __RAILS_ERB_LOADER_DELIMETER__ erbfor my
.erbfile. But it was giving me an error that rake was not found. It was an issue with spring. Disabling spring for the job worked.So in our case it was
DISABLE_SPRING=1 bin/webpackLink to the spring issue. https://github.com/rails/spring/pull/546
I’ve come across this error as well. In my case, the Rails Runner script was invoked with the global Ruby installation, not my local rbenv version.
bin/railshas the default shebang (#!/usr/bin/env ruby), which works in my default shell, but obviously not withspawn?The error message I got was
followed by
I’m still running Webpacker 2.0, so I could just modify my
config/webpacker/loaders/erb.js:I don’t know, however, why this became a problem today. When working on the very same project on the same machine last week, the webpack was built without hickups…
Hi @Swat123. I don’t know why this is happening exactly, but I can explain the general context of this error message and maybe we can improve the reporting or find out what’s going wrong.
When rails-erb-loader loads a single file:
0) then the loader succeeds and the transpiled source is given to webpack.Typically with Rails you’d use
bin/rails runnerto execute the transformer script, and you can see that this is the approach that webpacker uses.In short:
bin/rails runneris exiting with an error code.For @Swat123
I would have expected error output to be piped through to the main process, so you should see error logs on screen if they’re printed. Is there any logging before you see that error? If no, is it possible that the wrapper task you’re running is somehow suppressing stderr from webpack? I’m aware of webpacker’s existence, but I haven’t used it myself.
By “randomly” you mean that it only happens sometimes right? If this is the case it might be being caused by spring. You could try running the process with
DISABLE_SPRING=1and see if that stops it. It might make your build slower, but it would help explain the problem.You can either add it to your loader config:
Or you should be able to set it with your rails command:
(uh… actually looking at the above you might need to remove the explicit call to spring)
Good luck!
For rails-erb-loader
Even if this issue turns out to be out of our control, I’d like to know how we can improve the error reporting from the loader. At very least we should update the error message to something like:
It’s also unclear to me why the
'close'callback is being called instead of the'error'callback.Additionally I’d like to double check and add test coverage to ensure that we are indeed piping stderr through to the console successfully.
I’m commenting on https://github.com/usabilityhub/rails-erb-loader/issues/63#issuecomment-647127581 but it should be a starter for anyone who has issues with
rails-erb:It’s not a conflict but the thing is : rails-erb-loader calls the
rails runnercommand (https://guides.rubyonrails.org/command_line.html#rails-runner) to generate JS fromjs.erbtemplates.What it says:
So your app must be fully functionnal before calling
rake assets:precompilein any environment.To be sure: run your app locally but in
productionmode (rails -e production). If you have some issues here (Rails don’t start because of Zeitwerk or any other issues like environment variables)rake assets:precompilewill surely fail later. It also means that yourview.js.erbfile must contain valid Ruby/Rails code or it will fail too.Technically what it does is :
https://github.com/usabilityhub/rails-erb-loader/blob/master/index.js#L21 https://github.com/usabilityhub/rails-erb-loader/blob/master/index.js#L75 https://github.com/usabilityhub/rails-erb-loader/blob/master/erb_transformer.rb
You can even try it manually 😃
We’re getting this issue on CircleCI (works fine locally) and I’ve tried every variation of running a ruby command I can think of, both in the circle.yml and the runner options.
This is what we get when
rails-erb-loadertries to run.If we take out
rails-erb-loaderand the one erb file, we don’t get this error. It seems to be something to do with spawning the subcommand.I’ve tried
bundle exec bin/webpackandrake webpack:compileandbin/webpackand so on, and for the optionsbundle exec bin/rails runner,bin/rails runner, etc.Thanks for detailed response @n-rodriguez. This is correct (but you also need to pass “engine” and “delimiter” arguments to the erb_transformer.)
@yosupgurl In this case though there are no real surprises here (for me, the author of this module). You’re hitting issue #33. The runner doesn’t add anything to scope. You’ll see that error if you’re trying to call a function
renderwhich is not available. I don’t know how to do what you’re doing, but there is some discussion in #33 you can refer to.We always used
renderat runtime for serving requests, not for baking HTML into JS strings at build time. Are you sure that’s even a good idea? Why not just inline the HTML straight into this file. Basically if you want to use webpack then you shouldn’t be usingrenderandpartial, that’s the point. Use raw-loader on a HTML file or something.Also same general advice I gave above: This is not a good tool for web development, it’s a transitional tool for moving away from server-side helpers and into SPA land using the superior webpack system. It’s slow and bad and should really be used as minimally as possible (until someone volunteers some fixes).
FWIW, I resolved this issue by correcting a Zeitwork::NameError thrown while deploying to Heroku (Rails 6.0.3; Ruby 2.7.1p83; WSL [Ubuntu 18.04]) :
``on_file_autoloaded’: expected file /tmp/build_10e9581d550a3c3f1134ca4159ab62d0/app/controllers/admins/[snake_case].rb to define constant Admins::[CamelCase], but didn’t (Zeitwerk::NameError)`
My fix was simple: For each file that caused this error, I pluralized the module name (e.g., “Admins” instead of “Admin”) to resolve the error.
I’m not sure if there is a conflict between Zeitwork and rails-erb-loader, but this resolved compilation errors for TWO failing js.erb files.
In case it helps someone else having this issue, it was happening to me when trying to deploy to heroku using
../bin/rails runnerfor therunneroption. Along the lines of the suggestion in https://github.com/usabilityhub/rails-erb-loader/issues/63#issuecomment-392746607 changing it to../bin/bundle exec rails runnerfixed the issue.I have the same issue, very annoying.
I tried setting DISABLE_SPRING as well as NODE_ENV as indicated in this thread, to no avail.
This is my erb.js file:
I’ve also tried without the env and with preceding the DISABLE_SPRING to the runner.
I’m using version 5.5.2
For completeness this is the serviceworker.js.erb file:
var CACHE_VERSION = ‘v10’; var CACHE_NAME = CACHE_VERSION + ‘:sw-cache-’;
The webpack-dev-server is running fine, it’s only when deploying to production this is giving issues.
@bbugh also, is there any way of getting a full stack trace?
@andybluey
FYI you can always do this:
Where
devis your dev server “script”.@akaspick if you update to latest (5.4.2) you should get the name of the signal that killed your process in future. Hopefully you can check your production environment docs to find out what might be causing it.