-
Notifications
You must be signed in to change notification settings - Fork 28
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
Error: rails-erb-loader failed with code: 1 #63
Comments
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:
Typically with Rails you'd use In short: 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 You can either add it to your loader config: options: { runner: 'DISABLE_SPRING=1 bin/rails runner' } 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 Additionally I'd like to double check and add test coverage to ensure that we are indeed piping stderr through to the console successfully. |
Thank you so much. You are right it is spring. Disabling spring gets me rid of the error. Any way I can debug and pull in more trace info so that it can help others ? |
Hey @Swat123, thanks for getting back to me. Glad I could help. Yes, absolutely. If you're willing to put in some work there are a few actionables here...
Any effort on any of these would be greatly appreciated, thanks. :) |
I wonder if we can learn something from the |
I tried this for other ENV var that i needed and this does not work. |
@dreyks oh dear! |
I'm also affected by this with undecipherable errors. I will investigate and report back. |
Thanks @kofronpi. It's hard for me to investigate because I am not experiencing this issue at the moment. |
I'm going mad trying to deploy to a production env with rails-erb-loader...
My package.json:
Any ideas? There is nothing to tell me what actually went wrong. This is occurring on my production Ubuntu 14.04 server. |
Follow up to my last message... now compilation works with no changes to the server. Stress on the randomly in this issues title. I'll keep testing to see if there's any pattern to this... server load, etc. |
@akaspick I was on holiday. It seems our failure is here. child.on('close', function (code) {
if (code === 0) {
// ...
} else if (child.killed) {
// ...
} else {
callback(new Error('rails-erb-loader failed with code: ' + code))
}
}) Explanation here.
So should look like this: child.on('close', function (code, signal) { // <-- Add signal param here
if (code === 0) {
// ...
} else if (child.killed) { // <-- I'm _assuming_ this is the same as `signal === 'SIGKILL'`
// ...
} else if (signal !== null) { // <-- Add this handler
callback(new Error('rails-erb-loader terminated by signal: ' + signal))
} else {
callback(new Error('rails-erb-loader failed with code: ' + code))
}
}) @akaspick you should get more information if we implement these changes. I'm a little behind having just returned from a break. Are you up to making this change? |
@rhys-vdw I'd love to make the change, but I don't have a reliable way to reproduce the issue. I had non-stop issues one evening last week and then the following day and after I haven't seen the issue since. If this comes up again, I'll take another look. Thanks for the reply. |
@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. |
Setting NODE_ENV might save you : rails/webpacker#1374 |
I had the same error with erb-loader with
But it was weird because : $ 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__ erb
$ echo $?
0 Setting NODE_ENV saved my day :) |
@n-rodriguez so this is an issue with webpacker, not not rails-erb-loader? |
well it seems to be... |
I don't know how or why but when |
Thanks for the info. We don't use webpacker, but if there's anything we can do to prevent/report this error in the actual loader I'd appreciate the help. My understanding is that any stderr should be piped through to console when webpack is running, so if Rails is outputting errors via stdout they should be visible. That said this behaviour might be broken. |
@n-rodriguez - can you please let me know the change you made? Thanks |
Setting NODE_ENV env var saved my day :) |
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. The error message I got was
followed by
I'm still running Webpacker 2.0, so I could just modify my options: {
- runner: 'bin/rails runner',
+ runner: 'bundle exec bin/rails runner',
}, 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... |
Hey @n-rodriguez - sorry, just to confirm, where and how did you add NODE_ENV env var? Thnks |
In case it helps someone else having this issue, it was happening to me when trying to deploy to heroku using |
Just chiming in with my solution, for anyone that comes looking in the future. I ran into this issue trying to deploy a Rails 6 application to Dokku using ERB javascript templates. Everything worked great locally under development and production env settings, but when pushed to Dokku it would fail at the Ultimately, I discovered that my binstubs were not executable upon deploy. #fml This was the error I was getting.
|
Maybe add
Would be good to have |
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. |
Not sure another me too will help; but the error is in a new simple app in development mode. Here are all the gems including ones from development mode which I'm in. Using webpacker for JS and SCSS, but not for images. A new small tutorial app. But I wanted
And
Error in localhost:
Without the erb in the js script page loads fine. |
@MtnBiker are you sure the actual error isn't being printed out further up the build output? In any case I'd strongly advise against using this tool in a new stack, rails-erb-loader was designed as a stopgap for if you have legacy ERB from a sprockets project that is now being built w/ webpack. There are better ways to get image paths into your JS that don't require templating. Read the guide. |
@rhys-vdw Not sure about your first sentence. The error I showed is the only error in Chrome Console. But I'll take your advice. Many recommended against handling images with Webpacker, but I guess I'm pushing the limits, so will dive in. Part of it is the changing recommendations and to start with I don't have a Thank you for answering. EDIT for others as lacking in knowledge as I appears rails-erb-loader is added anyway, but .erb is not needed AFAIK. |
When you run webpack normally it just spits output into the console, and any error from the rails-erb-loader process is piped out to STDERR before the exception is fired. I can't recall if this output it included in Chrome.
I can't comment on webpacker, it's a gem that relies on this module but I've never used it. It's very normal to
My guess is that webpacker would be set up to handle images via |
I get this error message when attempting to compile a .js.erb file with webpacker.
My erb.js file looks like this.
I've tried a few solutions here, involving changing the path to 'ruby bin\ rails runner' since I'm on a windows machine, if I do that I get this error
I've tried adding
same ENOENT error. I've tried adding the below snippet to erb.js, same exit code: 1
I've also tried adding the helper in my transformer_erb file like such To no avail, not sure where to go from here. For context, i'm on WSL 2 running ubuntu 16. I've isolated my compiling error to these two lines of code.
|
I'm commenting on #63 (comment) but it should be a starter for anyone who has issues with
It's not a conflict but the thing is : rails-erb-loader calls the What it says:
So your app must be fully functionnal before calling To be sure: run your app locally but in Technically what it does is : # something like that
cat myfile | bin/rails runner <path to erb_transformer.rb> > output.js https://github.com/usabilityhub/rails-erb-loader/blob/master/index.js#L21 You can even try it manually :) |
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 We always used 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). |
@rhys-vdw I'm using pagy to paginate a list of items. I'm initializing the variable that contains the paginated list before I call the j render function, this should allow for this functionality, no? Sorry, I'm fairly new to web dev and I've been stuck on this for quite some time. None of the solutions allow me to properly render the paginated partial on click. Perhaps you could link me to a resource that would allow me to implement this feature? |
@mcmaddox and @n-rodriguez saved me on this in the end. Despite ALSO, for anyone coming here on a For a good time, add |
Hello everyone, any updates on this problem? "rails-erb-loader": "^5.5.2" my erb.js /* 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: {
timeoutMs: 20000,
runner: (/^win/.test(process.platform) ? "ruby " : "") + "bin/rails runner",
env: {
...process.env,
DISABLE_SPRING: 1,
},
},
}],
} My output on precompile, compile webpacker |
I think I made this change to force Ruby to output the error, but it never got merged. You could try making that modification to your |
I'm having the same problem on heroku with rails 6.1, it compiles with command RAILS_ENV=production assets:precompile on my machine, but when pushing to heroku the following error is displayed: ERROR in ./app/javascript/i18n-js/index.js.erb Module build failed (from ./node_modules/rails-erb-loader/index.js): Error: rails-erb-loader failed with code: 1 at ChildProcess. (/tmp/build_4d3416a8/node_modules/rails-erb-loader/index.js:128:16) at ChildProcess.emit (events.js:375:28) at maybeClose (internal/child_process.js:1055:16) at Socket. (internal/child_process.js:441:11) at Socket.emit (events.js:375:28) at Pipe. (net.js:675:12) @ ./app/javascript/packs/application.js 5:392-431 5:443-447 5:448-452 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. (/tmp/build_4d3416a8/node_modules/rails-erb-loader/index.js:128:16) at ChildProcess.emit (events.js:375:28) at maybeClose (internal/child_process.js:1055:16) at Socket. (internal/child_process.js:441:11) at Socket.emit (events.js:375:28) at Pipe. (net.js:675:12) |
In my case is while doing the docker image, could it be the same problem in heroku, because without the DISABLE_SPRING the problem is that ruby does not exists in the linux machine that im creating the docker, but thats the thing, it should not need ruby outside the docker to use ruby inside the docker |
@rcerqueira11AP I've already set DISABLE_SPRING=1 in heroku's environment variables, but it didn't do any good |
I had this issue with a PR that changed both the ruby version and rails version to After a lot of debugging I found that my error was before_script:
- echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p maybe this can help someone else having the same issues because this thread had me thinking it was a spring problem but in my case it was not since it's working without any |
After running webpack on a heroku bash session, I found out that there's something odd going on with the ARGV being passed to bin/rails...
It seems the process is receiving the following ARGV, which is logically incorrect per erb_transformer.rb
I think this is due to the eager loading that happens on production, for some reason |
@thiagobrandam see how i solved my problem jbox-web/ajax-datatables-rails#394 |
I ran into an issue that exemplifies the following statement given by @n-rodriguez, and wanted to highlight it.
On dev environment the erb-loader was working fine. The issue would appear only when deploying to Heroku review apps. The logs would show
for all
After hours of debugging, we found out that I couldn't find a way to overcome that by changing Heroku deploy configs. The solution was to remove this gem and use asset pipeline setup for this specific use case 😔. If anyone knows another solution for this please let me know. Thanks! |
So this module will just do whatever happens when you call However do you need to transpile your JS at this stage? Surely your backend doesn't rely on JS being compiled. Just run webpack as the last step after your database has been migrated.
This is not a gem, it's an npm package. If your issue is with webpacker, as opposed to this package, please raise issues there. I am not in control of how it's integrated in other packages. rails-erb-loader predates webpacker. Might I add that this was created so that we could stop using |
I tryied same error. I created repro this Dockerfile.zip. not found filename
error message #yarn build
Please specify a valid ruby command or the path of a script to run.
Run 'rails runner -h' for help.
/web/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3/lib/rails/commands/runner/runner_command.rb:46: syntax error, unexpected local variable or method, expecting end-of-input
...s-erb-loader-virtual-27b0bedac7/0/cache/rails-erb-loader-npm...
... ^~~~~~~~
assets by status 1.05 KiB [cached] 1 asset
runtime modules 663 bytes 3 modules
cacheable modules 63 bytes
./app/javascript/app.js 24 bytes [built] [code generated]
./app/javascript/myerb.js.erb 39 bytes [built] [code generated] [1 error]
ERROR in ./app/javascript/myerb.js.erb
Module build failed (from ./.yarn/__virtual__/rails-erb-loader-virtual-27b0bedac7/0/cache/rails-erb-loader-npm-5.5.2-8c1ad94c6e-f89ac4f14b.zip/node_modules/rails-erb-loader/index.js):
Error: rails-erb-loader failed with code: 1 webpack.config.js module: {
rules: [
{
test: /\.erb$/,
enforce: "pre",
loader: "rails-erb-loader",
options: {
runner: "bundle exec bin/rails runner"
}
}
]
}, environments
|
Per @rhys-vdw's comment
We ran into the same situation. For specifically this Heroku Review Apps + webpacker + rails-erb-loader issue, I think I solved by sort of monkey patching the Rake Task:
if ENV["RAILS_ENV"] == "review"
Rake::Task["assets:precompile"].enhance(["db:schema:load"])
end It does mean that |
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:
Package.json has following:
The text was updated successfully, but these errors were encountered: