Error: rails-erb-loader failed with code: 1
Opened this issue Β· 81 comments
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"
}
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:
- It runs a Ruby script in a new process. The script waits for data to be piped into it.
- rails-erb-loader streams the input file to the process via stdin
- The script transforms the source and prints it out.
- rails-erb-loader reads all the stdout from the script (this will be the output)
- When the process closes, if it ended without error (ie. returned code
0
) then the loader succeeds and the transpiled source is given to webpack.
Typically with Rails you'd use bin/rails runner
to execute the transformer script, and you can see that this is the approach that webpacker uses.
In short: bin/rails runner
is 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.
But I randomly get following error[...]
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=1
and 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:
options: { runner: 'DISABLE_SPRING=1 bin/rails runner' }
Or you should be able to set it with your rails command:
DISABLE_SPRING=1 ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/swathishah/shopify-app/bin/spring rails --trace assets:precompile
(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:
rails-erb-loader: "bin/rails runner" closed with exit code 1
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.
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...
- Improve the error message to include the actual executable that returned the error code (see my previous comment)
- Confirm that spring is actually not outputting any error information on stderr. My understanding is that we're reporting all information to the user at the moment, and you're seeing nothing in this case. There's a chance that spring is actually printing a meaningful error and we're accidentally suppressing it. If this is the case we might need to change the way we handle
stderr
. - Add a troubleshooting section to the README that suggests trying to disable spring for random failures/hangs. This should still suggest opening/commenting in issues so we can try to nail them down.
- Do some research to see if there are any relevant issues about spring failing silently with error code 1. Perhaps there is a known workaround or at least something we can link to in the README.
Any effort on any of these would be greatly appreciated, thanks. :)
I wonder if we can learn something from the spring server
command...
options: { runner: 'DISABLE_SPRING=1 bin/rails runner' }
I tried this for other ENV var that i needed and this does not work. parseRunner
splits by spaces so the ENV var becomes a file that spawn
tries to call
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...
ERROR in ./app/javascript/packs/components/repeat_dialog.vue.erb
Module build failed: Error: rails-erb-loader failed with code: null
at ChildProcess.<anonymous> (/home/deploy/app/releases/353/node_modules/rails-erb-loader/index.js:108:16)
at ChildProcess.emit (events.js:182:13)
at maybeClose (internal/child_process.js:947:16)
at Socket.stream.socket.on (internal/child_process.js:368:11)
at Socket.emit (events.js:182:13)
at Pipe._handle.close [as _onclose] (net.js:598:12)
Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js??ref--1-2!node_modules/postcss-loader/lib/index.js??ref--1-3!node_modules/bootstrap-daterangepicker/daterangepicker.css:
2 modules
Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js??ref--1-2!node_modules/postcss-loader/lib/index.js??ref--1-3!node_modules/fullcalendar/dist/fullcalendar.min.css:
2 modules
Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js??ref--1-2!node_modules/postcss-loader/lib/index.js??ref--1-3!node_modules/fullcalendar-scheduler/dist/scheduler.min.css:
2 modules
Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js??ref--1-2!node_modules/postcss-loader/lib/index.js??ref--1-3!node_modules/select2/dist/css/select2.min.css:
2 modules
Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js?minimize!node_modules/vue-loader/lib/style-compiler/index.js?{"optionsId":"0","vue":true,"scoped":false,"sourceMap":false}!node_modules/sass-loader/lib/loader.js!node_modules/vue-loader/lib/selector.js?type=styles&index=0!app/javascript/packs/components/target_table.vue:
2 modules
Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js?minimize!node_modules/vue-loader/lib/style-compiler/index.js?{"optionsId":"0","vue":true,"id":"data-v-3dc4e503","scoped":true,"sourceMap":false}!node_modules/sass-loader/lib/loader.js!node_modules/vue-loader/lib/selector.js?type=styles&index=0!app/javascript/packs/components/target_input.vue:
2 modules
Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js?minimize!node_modules/vue-loader/lib/style-compiler/index.js?{"optionsId":"0","vue":true,"id":"data-v-25afaeb2","scoped":true,"sourceMap":false}!node_modules/sass-loader/lib/loader.js!node_modules/vue-loader/lib/selector.js?type=styles&index=1!app/javascript/packs/components/target_table.vue:
2 modules
My package.json:
{
"dependencies": {
"@rails/webpacker": "3.5",
"bootstrap-daterangepicker": "^2.1.25",
"caniuse-lite": "^1.0.30000697",
"coffeescript": "1.12.7",
"css-loader": "^0.28.11",
"expose-loader": "^0.7.3",
"file-loader": "^0.11.2",
"foundation-datepicker": "^1.5.6",
"fullcalendar": "^3.4.0",
"fullcalendar-scheduler": "^1.6.2",
"jquery": "^3.2.1",
"moment": "^2.18.1",
"rails-erb-loader": "^5.4.1",
"select2": "^4.0.3",
"slm": "^1.0.0",
"vue": "^2.5.16",
"vue-loader": "14.2.2",
"vue-template-compiler": "^2.5.16",
"webpack": "^3.0.0"
},
"devDependencies": {
"webpack-dev-server": "2.11.2"
}
}
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.
If the process exited,
code
is the final exit code of the process, otherwisenull
. If the process terminated due to receipt of a signal,signal
is the string name of the signal, otherwisenull
. One of the two will always be non-null.
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 bundle exec rake assets:precompile
:
ERROR in ./app/javascript/vendor/javascripts/smart_listing/smart_listing.coffee.erb
Module build failed: Error: rails-erb-loader failed with code: 1
at ChildProcess.<anonymous> (/home/nicolas/PROJECTS/CONCERTO/concerto/node_modules/rails-erb-loader/index.js:120:16)
at ChildProcess.emit (events.js:182:13)
at maybeClose (internal/child_process.js:957:16)
at Socket.stream.socket.on (internal/child_process.js:378:11)
at Socket.emit (events.js:182:13)
at Pipe._handle.close [as _onclose] (net.js:598:12)
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?
@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 rails/runner
is called by rails-erb-loader the exit code is not 0.
Running it by hand returns 0.
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. bin/rails
has the default shebang (#!/usr/bin/env ruby
), which works in my default shell, but obviously not with spawn
?
The error message I got was
12% building modules 22/25 modules 3 active $RAILS_ROOT/app/javascript/i18n.js.erb
Ignoring bcrypt-3.1.12 because its extensions are not built. Try: gem pristine bcrypt --version 3.1.12
Ignoring bcrypt_pbkdf-1.0.0 because its extensions are not built. Try: gem pristine bcrypt_pbkdf --version 1.0.0
Ignoring binding_of_caller-0.8.0 because its extensions are not built. Try: gem pristine binding_of_caller --version 0.8.0
$RBENV_GEMSET_DIR/gems/bundler-1.16.2/lib/bundler/spec_set.rb:91:in `block in materialize': Could not find nokogiri-1.8.2 in any of the sources (Bundler::GemNotFound)
from $RBENV_GEMSET_DIR/gems/bundler-1.16.2/lib/bundler/spec_set.rb:85:in `map!'
from $RBENV_GEMSET_DIR/gems/bundler-1.16.2/lib/bundler/spec_set.rb:85:in `materialize'
from $RBENV_GEMSET_DIR/gems/bundler-1.16.2/lib/bundler/definition.rb:171:in `specs'
from $RBENV_GEMSET_DIR/gems/bundler-1.16.2/lib/bundler/definition.rb:238:in `specs_for'
from $RBENV_GEMSET_DIR/gems/bundler-1.16.2/lib/bundler/definition.rb:227:in `requested_specs'
from $RBENV_GEMSET_DIR/gems/bundler-1.16.2/lib/bundler/runtime.rb:108:in `block in definition_method'
from $RBENV_GEMSET_DIR/gems/bundler-1.16.2/lib/bundler/runtime.rb:20:in `setup'
from $RBENV_GEMSET_DIR/gems/bundler-1.16.2/lib/bundler.rb:107:in `setup'
from $RBENV_GEMSET_DIR/gems/bundler-1.16.2/lib/bundler/setup.rb:20:in `<top (required)>'
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
from $RAILS_ROOT/config/boot.rb:3:in `<top (required)>'
from bin/rails:3:in `require_relative'
from bin/rails:3:in `<main>'
followed by
ERROR in ./app/javascript/i18n.js.erb
Module build failed: Error: rails-erb-loader failed with code: 1
at ChildProcess.<anonymous> ($RAILS_ROOT/node_modules/rails-erb-loader/index.js:120:16)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at maybeClose (internal/child_process.js:925:16)
at Socket.stream.socket.on (internal/child_process.js:346:11)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at Pipe._handle.close [as _onclose] (net.js:557:12)
@ ./app/javascript/packs/frontend.js 119:0-37
@ multi (webpack)-dev-server/client?http://0.0.0.0:8080 babel-polyfill ./app/javascript/packs/frontend.js
I'm still running Webpacker 2.0, so I could just modify my config/webpacker/loaders/erb.js
:
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
@andybluey I use Dotenv gem
@rhys-vdw: Is $PATH
affected as well?
In my case $PATH
contains $HOME/.rbenv/shims
before /usr/bin
, so that /usr/bin/env ruby
(the shebang of bin/rails
) picks up $HOME/.rbenv/shims/ruby
, which in turn reads my local rbenv config (Ruby version + gemset name), and finally resolves ruby
to $HOME/.rbenv/versions/ruby-2.3/bin/ruby
.
When calling Node's spawn
function in transformSource()
, the $PATH
seems not to be passed (docs say, options.env
defaults to process.env
). I'm not sure if I'm reading something wrong, but I don't see why the $PATH
of bin/webpack-dev-server
should not be the same when invoking bin/rails
in the rails-erb-loader (I'm missing a huge chunk of code named webpack between executing those commands though :-))
@dmke I wouldn't expect $PATH
to change for reasons you've listed. How are you invoking webpack though? Using webpacker
? Maybe it's doing something funky.
FYI you can always do this:
$ NODE_ENV=development npm run dev
Where dev
is your dev server "script".
I'm also facing this issue when deploying to Heroku.
remote: Running: rake assets:precompile
remote: yarn install v1.5.1
remote: [1/4] Resolving packages...
remote: [2/4] Fetching packages...
remote: info fsevents@1.2.4: The platform "linux" is incompatible with this module.
remote: info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation.
remote: [3/4] Linking dependencies...
remote: warning "@rails/webpacker > postcss-cssnext@3.1.0" has unmet peer dependency "caniuse-lite@^1.0.30000697".
remote: warning "@rails/webpacker > webpack-assets-manifest@3.0.1" has unmet peer dependency "webpack-sources@^1.0".
remote: warning " > rails-erb-loader@5.4.2" has unmet peer dependency "webpack@^2.0.0 || >= 3.0.0-rc.0 || ^3.0.0".
remote: warning " > webpack-dev-server@3.1.4" has unmet peer dependency "webpack@^4.0.0-beta.1".
remote: warning "webpack-dev-server > webpack-dev-middleware@3.1.3" has unmet peer dependency "webpack@^4.0.0".
remote: [4/4] Building fresh packages...
remote: Done in 30.74s.
remote: Webpacker is installed π π°
remote: Using /tmp/build_2fd1132ac534cf5d82a21025657aba3d/config/webpacker.yml file for setting up webpack paths
remote: Compilingβ¦
remote: Compilation failed:
remote: Hash: 5155e8b55fcc41263913
remote: Version: webpack 4.10.2
remote: Time: 3632ms
remote: Built at: 2018-06-05 17:25:34
remote: 6 assets
remote: [0] ./app/javascript/packs/hello_react.jsx.erb 539 bytes {0} [built] [failed] [1 error]
remote: [2] ./app/javascript/stylesheets/application.scss 39 bytes {1} [built]
remote: [3] ./app/javascript/packs/application.js 558 bytes {1} [built]
remote: + 1 hidden module
remote:
remote: ERROR in ./app/javascript/packs/hello_react.jsx.erb
remote: Module build failed: Error: rails-erb-loader failed with code: 1
remote: at ChildProcess.<anonymous> (/tmp/build_2fd1132ac534cf5d82a21025657aba3d/node_modules/rails-erb-loader/index.js:120:16)
remote: at emitTwo (events.js:126:13)
remote: at ChildProcess.emit (events.js:214:7)
remote: at maybeClose (internal/child_process.js:925:16)
remote: at Socket.stream.socket.on (internal/child_process.js:346:11)
remote: at emitOne (events.js:116:13)
remote: at Socket.emit (events.js:211:7)
remote: at Pipe._handle.close [as _onclose] (net.js:567:12)
I'm using rails-webpacker (with webpacker 4.10.2). I know it's not supported yet by erb-loader, but I've been using it without problems in development. The strangest part is that when I run this command it finishes without problem:
RAILS_ENV=production NODE_ENV=production ./bin/webpack --progress --config config/webpack/production.js
I also run NODE_ENV=production RAILS_ENV=production bundle exec rails assets:precompile
with no errors.
I tried setting DISABLE_SPRING=1 in heroku but it's still not working.
I created a project that can reproduce this error: https://github.com/luislezcair/erb-loader-test when pushing to Heroku.
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-loader
tries to run.
/usr/local/lib/ruby/site_ruby/2.5.0/bundler/spec_set.rb:91:in `block in materialize': Could not find rake-12.3.1 in any of the sources (Bundler::GemNotFound)
If we take out rails-erb-loader
and 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/webpack
and rake webpack:compile
and bin/webpack
and so on, and for the options bundle exec bin/rails runner
, bin/rails runner
, etc.
I'm using rails-webpacker (with webpacker 4.10.2). I know it's not supported yet by erb-loader
Webpacker depends on rails-erb-loader but I am not a member of the project. There is no "yet" - this project is a webpack loader, and that's all it is. My support starts and ends with this repository.
I'd like to look into the error reproduction, but I'm quite busy. I need to deploy it to heroku to see the failure right?
So sorry about that, I'd copied the stack trace to the clipboard but never pasted it in.
I think that it's related because I'm getting the same error message as this thread title, and in my particular case the spawned child seems to not be using the correct environment, which I believe someone else mentioned as well.
In the stack trace, you can see that webpack is trying to compile vue-apollo.js.erb
which uses some Rails configuration via ERB. When it tries to compile that, it breaks with the code: 1
issue in the child process.
Stack trace
/usr/local/lib/ruby/site_ruby/2.5.0/bundler/spec_set.rb:91:in `block in materialize': Could not find rake-12.3.1 in any of the sources (Bundler::GemNotFound)
from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/spec_set.rb:85:in `map!'
from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/spec_set.rb:85:in `materialize'
from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/definition.rb:171:in `specs'
from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/definition.rb:238:in `specs_for'
from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/definition.rb:227:in `requested_specs'
from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/runtime.rb:108:in `block in definition_method'
from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/runtime.rb:20:in `setup'
from /usr/local/lib/ruby/site_ruby/2.5.0/bundler.rb:107:in `setup'
from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/setup.rb:20:in `<top (required)>'
from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from /home/circleci/circleci-demo-ruby-rails/vendor/bundle/gems/spring-2.0.2/lib/spring/commands.rb:33:in `<module:Spring>'
from /home/circleci/circleci-demo-ruby-rails/vendor/bundle/gems/spring-2.0.2/lib/spring/commands.rb:4:in `<top (required)>'
from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from /home/circleci/circleci-demo-ruby-rails/vendor/bundle/gems/spring-2.0.2/lib/spring/application.rb:87:in `preload'
from /home/circleci/circleci-demo-ruby-rails/vendor/bundle/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
from /home/circleci/circleci-demo-ruby-rails/vendor/bundle/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
from /home/circleci/circleci-demo-ruby-rails/vendor/bundle/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
from /home/circleci/circleci-demo-ruby-rails/vendor/bundle/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
from /home/circleci/circleci-demo-ruby-rails/vendor/bundle/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from -e:1:in `<main>'
Hash: 8e99c16d180d8a93fe43
Version: webpack 3.12.0
Time: 13001ms
Asset Size Chunks Chunk Names
frontend-5f47b714ae55d40a6f0d.js 2.89 MB 0 [emitted] [big] frontend
frontend-2a7c4b6da6b929b4f26b962703a6b7ab.css 292 kB 0 [emitted] [big] frontend
frontend-5f47b714ae55d40a6f0d.js.map 3.17 MB 0 [emitted] frontend
frontend-2a7c4b6da6b929b4f26b962703a6b7ab.css.map 485 kB 0 [emitted] frontend
manifest.json 306 bytes [emitted]
[12] (webpack)/buildin/global.js 509 bytes {0} [built]
[39] ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./app/javascript/App.vue 974 bytes {0} [built]
[97] ./app/javascript/packs/frontend.js 510 bytes {0} [built]
[98] ./app/javascript/main.js 1.61 kB {0} [built]
[102] ./app/javascript/App.vue 2.03 kB {0} [built]
[117] ./app/javascript/router.js 2.64 kB {0} [built]
[186] ./app/javascript/views/NewLineItem.vue 2.1 kB {0} [built]
[192] ./app/javascript/views/NotFound.vue 2.08 kB {0} [built]
[195] ./app/javascript/filters.js 585 bytes {0} [built]
[196] ./app/javascript/vue-apollo.js.erb 535 bytes {0} [built] [failed] [1 error]
[310] ./app/javascript/assets/bootstrap.scss 41 bytes {0} [built]
[312] ./app/javascript/config .js$ 221 bytes {0} [built]
[315] ./app/javascript/config/vue-error-page.js 554 bytes {0} [optional] [built]
[319] ./app/javascript/config/vuelidate.js 317 bytes {0} [optional] [built]
[348] ./node_modules/css-loader??ref--2-2!./node_modules/postcss-loader/lib??ref--2-3!./node_modules/sass-loader/lib/loader.js??ref--2-4!./app/javascript/assets/bootstrap.scss 649 kB [built]
+ 337 hidden modules
ERROR in ./app/javascript/vue-apollo.js.erb
Module build failed: Error: rails-erb-loader failed with code: 1
at ChildProcess.<anonymous> (/home/circleci/circleci-demo-ruby-rails/node_modules/rails-erb-loader/index.js:120:16)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at maybeClose (internal/child_process.js:925:16)
at Socket.stream.socket.on (internal/child_process.js:346:11)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at Pipe._handle.close [as _onclose] (net.js:557:12)
@ ./app/javascript/main.js 21:19-49
@ ./app/javascript/packs/frontend.js
@rhys-vdw Yes, the repo I uploaded reproduces the issue when deploying to Heroku. It works fine locally.
@luislezcair did you notice that you have some ERB in a comment? Any chance that's an issue?
Okay, yeah, this is happening a lot... If you're consistently experiencing this issue, could you please try getting more info out of the transformer.rb
...
Perhaps we can wrap the whole file in a begin
/rescue
block that prints out the error message to stdout
.
The other possibility is that it's just spring breaking before the script is even executed.
I created a project that can reproduce this error: https://github.com/luislezcair/erb-loader-test when pushing to Heroku.
@luislezcair is there much involved in trying to deploy it? Was hoping for some instructions in the README.
I think I may be getting closer to the problem. In fact, the ERB in a comment you mentioned was causing the error, but in my actual project I need to call asset_pack_path
helper wich is in Webpacker::Helper
module, the same as javascript_pack_tag
.
What I suspect is happening is that the .js.erb
file wich calls asset_pack_path
helper is getting compiled before the asset (image/7.jpg
), so when I call asset_pack_path('image/7.jpg')
, Webpack cannot find it (because it wasn't processed yet) and erb-loader fails. Then, Webpack process the image, so in a second run of ./bin/webpack --progress
the image is already there and erb-loaders succeeds. This is why I thought it was working locally, because I was not deleting the public/packs
directory where Webpack saves the compiled assets.
I'm new to Webpack and I couldn't find a way to tell Webpack to process the image assets (with file-loader
) before the erb files.
The odd part is that when erb-loader fails it gives the following trace (stack level too deep):
10% building modules 2/3 modules 1 active β¦erb_test/app/javascript/erb_test.js.erbRunning via Spring preloader in process 2540
Traceback (most recent call last):
9362: from -e:1:in `<main>'
9361: from /home/luis/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
9360: from /home/luis/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
9359: from /home/luis/Proyectos/Ruby/erb_test/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:277:in `load'
9358: from /home/luis/Proyectos/Ruby/erb_test/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'
9357: from /home/luis/Proyectos/Ruby/erb_test/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:277:in `block in load'
9356: from /home/luis/Proyectos/Ruby/erb_test/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
9355: from /home/luis/Proyectos/Ruby/erb_test/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
... 9350 levels...
4: from /home/luis/Proyectos/Ruby/erb_test/vendor/bundle/ruby/2.5.0/gems/actionview-5.2.0/lib/action_view/helpers/controller_helper.rb:16:in `request_forgery_protection_token'
3: from /home/luis/Proyectos/Ruby/erb_test/vendor/bundle/ruby/2.5.0/gems/actionview-5.2.0/lib/action_view/helpers/controller_helper.rb:16:in `request_forgery_protection_token'
2: from /home/luis/Proyectos/Ruby/erb_test/vendor/bundle/ruby/2.5.0/gems/actionview-5.2.0/lib/action_view/helpers/controller_helper.rb:16:in `request_forgery_protection_token'
1: from /home/luis/Proyectos/Ruby/erb_test/vendor/bundle/ruby/2.5.0/gems/actionview-5.2.0/lib/action_view/helpers/controller_helper.rb:16:in `request_forgery_protection_token'
/home/luis/Proyectos/Ruby/erb_test/node_modules/rails-erb-loader/erb_transformer.rb:17:in `eval': stack level too deep (SystemStackError)
Hash: 20a987ceae3db8edf514
Version: webpack 4.10.2
Time: 1702ms
Built at: 06/06/2018 23:38:22
Asset Size Chunks Chunk Names
images/7-f9e66d23438ea709be513b60f66dcb17.jpg 2.01 KiB [emitted]
application-3abe88a1268bd8366b68.js 5.56 KiB application [emitted] application
application-3abe88a1268bd8366b68.js.map 3.82 KiB application [emitted] application
manifest.json 216 bytes [emitted]
[./app/javascript/erb_test.js.erb] 377 bytes {application} [built] [failed] [1 error]
[./app/javascript/images/7.jpg] 91 bytes {application} [built]
[./app/javascript/packs/application.js] 54 bytes {application} [built]
ERROR in ./app/javascript/erb_test.js.erb
Module build failed: Error: rails-erb-loader failed with code: 1
at ChildProcess.<anonymous> (/home/luis/Proyectos/Ruby/erb_test/node_modules/rails-erb-loader/index.js:120:16)
at ChildProcess.emit (events.js:182:13)
at maybeClose (internal/child_process.js:961:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5)
@ ./app/javascript/packs/application.js 2:0-28
I uploaded a simpler example to reproduce the error and updated the README with instructions on how to deploy to Heroku, but I was able to reproduce it locally this time.
@luislezcair Nice!
I think I may be getting closer to the problem.
π!
when I call asset_pack_path('image/7.jpg'), Webpack cannot find it (because it wasn't processed yet) and erb-loader fails
Right, so does it fail silently? Or is rails-erb-loader somehow hiding the error? I would expect that to be forwarded via stderr!
I'm new to Webpack and I couldn't find a way to tell Webpack to process the image assets (with file-loader) before the erb files.
You need to change the order of your config.module.rules
so that they go from lowest to highest priority. eg:
const config = {
// ... other config ...
module: {
rules: [
// ... other rules ...
{
test: /\.erb$/,
use: {
loader: "rails-erb-loader",
options: { timeoutMs: 20000 },
},
},
{
test: /\.(aac|bmp|eot|gif|ico|jpg|m4a|m4v|mp3|mp4|oga|ogg|oggv|otf|png|svg|ttf|wav|webm|webp|woff|woff2)$/,
use: {
loader: "file-loader",
options: {
name: "[name].[hash].[ext]",
},
},
},
]
// ... other config ...
}
module.exports = config
The odd part is that when erb-loader fails it gives the following trace
@luislezcair I don't know what to make of that, sorry, but thanks for including it.
you're getting Stack level to deep. which means you probably have an infinite recursive method call
I tried changing the order of the loaders following the webpacker docs but the issue persist.
environment.loaders.insert('erb', erb, { before: 'file' })
Using the rails console I found that the asset_pack_path
helper is the culprit of the recursive call that produces the stack error I posted before. When it doesn't find the asset, it tries to compile it, maybe?
$ bundle exec rails c
Running via Spring preloader in process 1226
Loading development environment (Rails 5.2.0)
[1] pry(main)> include ActionView::Helpers
=> Object
[2] pry(main)> include Webpacker::Helper
=> Object
[3] pry(main)> asset_pack_path 'images/7.jpg'
**Compilingβ¦**
SystemStackError: stack level too deep
from /home/luis/Proyectos/Ruby/erb_test/vendor/bundle/ruby/2.5.0/gems/actionview-5.2.0/lib/action_view/helpers/controller_helper.rb:16:in `request_forgery_protection_token'
[4] pry(main)>
yes, this won't work in webpacker with calls to packs: when encountering asset_pack_tag webpacker kicks off another round of "compile all" which includes your erb and that leads to stack overflow
Okay, so it sounds like that's an problem with webpacker. This issue is meant to be for errors that don't provide any info (stack trace, error message etc). So please comment in this thread if you're experiencing such a problem.
So, I just hit this. I see now what we're doing wrong:
[130] -> yarn run dev
yarn run v1.7.0
$ nvc && TS_NODE_PROJECT=config/webpack/tsconfig.json webpack-dev-server --hot --config config/webpack/app-config.ts --mode development
info: Node version matches the engine version
10% building modules 3/3 modules 0 active(node:23161) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
βΉ ο½’wdsο½£: Project is running at http://0.0.0.0:3808/
βΉ ο½’wdsο½£: webpack output is served from //localhost:3808/webpack_assets/
48% building modules 319/336 modules 17 active β¦ore-js/modules/es6.typed.int32-array.jsβΉ ο½’atlο½£: Using typescript@2.9.2 from typescript
βΉ ο½’atlο½£: Using tsconfig.json from /Users/rhys/Projects/usability-hub/usability_hub/tsconfig.json
65% building modules 650/709 modules 59 active β¦p/assets/javascripts/utilities/array.tsDEPRECATION WARNING on line 2, column 8 of stdin:
uding .cs 65% building modules 651/709 modules 58 active β¦p/assets/javascripts/utilities/array.tss files with @import is non-standard behaviour which will be removed in future versions of LibSass.
Use a custom importer to maintain this behaviour. Check your implementations documentation on how to create a custom importer.
65% building modules 697/755 modules 58 active β¦ty_hub/node_modules/lodash/_assocSet.jsWARNING on line 107, column 40 of /Users/rhys/Projects/usability-hub/usability_hub/node_modules/bourbon-neat/app/assets/stylesheets/grid/_omega.scss:
In Sass, "&&" means two copies of the parent selector. You probably want to use "and" instead.
65% building modules 706/762 modules 56 active β¦ode_modules/lodash/_assignInDefaults.jsWARNING on line 107, column 40 of /Users/rhys/Projects/usability-hub/usability_hub/node_modules/bourbon-neat/app/assets/stylesheets/grid/_omega.scss:
In Sass, "&&" means two copies of the parent selector. You probably want to use "and" instead.
66% building modules 1341/1417 modules 76 active β¦/node_modules/lodash-es/_setCacheHas.js/Users/rhys/.gem/ruby/2.4.4/gems/pg-1.0.0/lib/pg.rb:56:in `initialize': could not connect to server: Connection refused (PG::ConnectionBad)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
from /Users/rhys/.gem/ruby/2.4.4/gems/pg-1.0.0/lib/pg.rb:56:in `new'
from /Users/rhys/.gem/ruby/2.4.4/gems/pg-1.0.0/lib/pg.rb:56:in `connect'
from /Users/rhys/.gem/ruby/2.4.4/gems/activerecord-5.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:697:in `connect'
from /Users/rhys/.gem/ruby/2.4.4/gems/activerecord-5.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:221:in `initialize'
from /Users/rhys/.gem/ruby/2.4.4/gems/activerecord-5.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:38:in `new'
from /Users/rhys/.gem/ruby/2.4.4/gems/activerecord-5.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:38:in `postgresql_connection'
from /Users/rhys/.gem/ruby/2.4.4/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:759:in `new_connection'
from /Users/rhys/.gem/ruby/2.4.4/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:803:in `checkout_new_connection'
from /Users/rhys/.gem/ruby/2.4.4/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:782:in `try_to_checkout_new_connection'
from /Users/rhys/.gem/ruby/2.4.4/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:743:in `acquire_connection'
from /Users/rhys/.gem/ruby/2.4.4/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:500:in `checkout'
from /Users/rhys/.gem/ruby/2.4.4/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `connection'
from /Users/rhys/.gem/ruby/2.4.4/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `retrieve_connection'
from /Users/rhys/.gem/ruby/2.4.4/gems/activerecord-5.1.6/lib/active_record/connection_handling.rb:116:in `retrieve_connection'
from /Users/rhys/.gem/ruby/2.4.4/gems/activerecord-5.1.6/lib/active_record/connection_handling.rb:88:in `connection'
from /Users/rhys/Projects/usability-hub/usability_hub/config/environments/development.rb:50:in `block in <top (required)>'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/railtie.rb:211:in `instance_eval'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/railtie.rb:211:in `configure'
from /Users/rhys/Projects/usability-hub/usability_hub/config/environments/development.rb:1:in `<top (required)>'
from /Users/rhys/.gem/ruby/2.4.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
from /Users/rhys/.gem/ruby/2.4.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `block in require'
from /Users/rhys/.gem/ruby/2.4.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:258:in `load_dependency'
from /Users/rhys/.gem/ruby/2.4.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/engine.rb:600:in `block (2 levels) in <class:Engine>'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/engine.rb:599:in `each'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/engine.rb:599:in `block in <class:Engine>'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `run'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/initializable.rb:59:in `block in run_initializers'
from /Users/rhys/.rubies/ruby-2.4.4/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each'
from /Users/rhys/.rubies/ruby-2.4.4/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /Users/rhys/.rubies/ruby-2.4.4/lib/ruby/2.4.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
from /Users/rhys/.rubies/ruby-2.4.4/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /Users/rhys/.rubies/ruby-2.4.4/lib/ruby/2.4.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/initializable.rb:48:in `each'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/initializable.rb:48:in `tsort_each_child'
from /Users/rhys/.rubies/ruby-2.4.4/lib/ruby/2.4.0/tsort.rb:415:in `call'
from /Users/rhys/.rubies/ruby-2.4.4/lib/ruby/2.4.0/tsort.rb:415:in `each_strongly_connected_component_from'
from /Users/rhys/.rubies/ruby-2.4.4/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /Users/rhys/.rubies/ruby-2.4.4/lib/ruby/2.4.0/tsort.rb:347:in `each'
from /Users/rhys/.rubies/ruby-2.4.4/lib/ruby/2.4.0/tsort.rb:347:in `call'
from /Users/rhys/.rubies/ruby-2.4.4/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component'
from /Users/rhys/.rubies/ruby-2.4.4/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each'
from /Users/rhys/.rubies/ruby-2.4.4/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/initializable.rb:58:in `run_initializers'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/application.rb:353:in `initialize!'
from /Users/rhys/Projects/usability-hub/usability_hub/config/environment.rb:7:in `<top (required)>'
from /Users/rhys/.gem/ruby/2.4.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
from /Users/rhys/.gem/ruby/2.4.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `block in require'
from /Users/rhys/.gem/ruby/2.4.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:258:in `load_dependency'
from /Users/rhys/.gem/ruby/2.4.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/application.rb:329:in `require_environment!'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/command/actions.rb:16:in `require_application_and_environment!'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/commands/runner/runner_command.rb:27:in `perform'
from /Users/rhys/.gem/ruby/2.4.4/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
from /Users/rhys/.gem/ruby/2.4.4/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
from /Users/rhys/.gem/ruby/2.4.4/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/command/base.rb:63:in `perform'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/command.rb:44:in `invoke'
from /Users/rhys/.gem/ruby/2.4.4/gems/railties-5.1.6/lib/rails/commands.rb:16:in `<top (required)>'
from ./bin/rails:9:in `require'
from ./bin/rails:9:in `<main>'
67% building modules 1606/1685 modules 79 active β¦sults/question-test-section-results.tsxDEPRECATION WARNING on line 32, column 8 of stdin:
Including .css files with @import is non-standard behaviour which will be removed in future versions of LibSass.
Use a custom importer to maintain this behaviour. Check your implementations documentation on how to create a custom importer.
66% building modules 1690/1781 modules 91 active β¦ct-flip-move/dist/react-flip-move.es.jsDEPRECATION WARNING on line 33, column 8 of stdin:
Including .css files with @import is non-standard behaviour which will be removed in future versions of LibSass.
Use a custom importer to maintain this behaviour. Check your implementations documentation on how to create a custom importer.
94% after sealβΉ ο½’atlο½£: Checking started in a separate process...
βΉ ο½’atlο½£: Time: 6832ms
β ο½’wdmο½£: 2763 modules
ERROR in ./app/assets/javascripts/rails-routes.js.erb
Module build failed (from ./node_modules/rails-erb-loader/index.js):
Error: rails-erb-loader failed with code: 1
at ChildProcess.<anonymous> (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/rails-erb-loader/index.js:108:16)
at ChildProcess.emit (events.js:182:13)
at maybeClose (internal/child_process.js:961:16)
at Socket.stream.socket.on (internal/child_process.js:380:11)
at Socket.emit (events.js:182:13)
at Pipe._handle.close (net.js:598:12)
βΉ ο½’wdmο½£: Failed to compile.
Although the error is being printed, it's done while the progress is showing because it's being piped straight to stderr
, so the stack trace is not grouped with the failed with code: 1
error! A possible improvement here would be to buffer the stderr
and include it with the failure error.
For anyone else hitting this make sure you scroll up to see possible error messages from Ruby in the webpack output.
Hey @bbugh, I've got stuck with the same issue on CircleCI, did you find the way to resolve it?
@rkotov93 sorry no, we ended up removing it because of the instability. We ended up using environment variables to pass data.
We had a similar problem with erb-loader
on 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__ erb
for my .erb
file. 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/webpack
Link to the spring issue.
rails/spring#546
Our issue was also related to spring, but running GitLab pipelines. Had to run bundle install --without development
on our pipeline job to get it to work.
I had a similar issue with one of the projects I'm working on (rails based).
None of the solutions mentioned here worked for us, so I went into debugging mode... and found a commit that broke everything.
I managed to downgrade some of the gems, not sure which gem exactly broke rails-erb-loader -- but my best bet is autoprefixer-rails
(locked to 9.6.1.1) or rails-html-sanitizer
( locked to 1.2.0).
@skatkov
I use both of them fully updated
- autoprefixer-rails (9.7.1)
- rails-html-sanitizer (1.3.0)
But I use rails 5.2.3
Is there no way to rename application.js to application.js.erb with this software?? It works fine with the example but I'm trying to use it to import gems in my application.js, not import other js files with erb in them. It looks like it did work at some point according to this comment: nathanvda/cocoon#452 (comment). Is this not a thing anymore? All I get is this useless error message.
In my instance, this error was due to a ruby version bump which was identified easily as @rhys-vdw pointed out after running: bin/rails runner
.
I have the same issue, very annoying.
ERROR in ./app/javascript/packs/serviceworker.js.erb
Module build failed (from ./node_modules/rails-erb-loader/index.js):
Error: rails-erb-loader failed with code: 1
at ChildProcess.<anonymous> (/home/app/webapp/node_modules/rails-erb-loader/index.js:128:16)
at ChildProcess.emit (events.js:198:13)
at maybeClose (internal/child_process.js:982:16)
at Socket.stream.socket.on (internal/child_process.js:389:11)
at Socket.emit (events.js:198:13)
at Pipe._handle.close (net.js:607:12)
I tried setting DISABLE_SPRING as well as NODE_ENV as indicated in this thread, to no avail.
This is my erb.js file:
module.exports = {
test: /\.erb$/,
enforce: 'pre',
exclude: /node_modules/,
use: [{
loader: 'rails-erb-loader',
options: {
runner: 'bin/rails runner',
env: { DISABLE_SPRING: 1, NODE_ENV: 'development' }
}
}]
}
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-';
function onInstall(event) {
console.log('[Serviceworker]', "Installing!", event);
event.waitUntil(
caches.open(CACHE_NAME).then(function prefill(cache) {
return cache.addAll([
<% helpers = ActionController::Base.helpers %>
'<%= helpers.asset_pack_path "application.js" %>',
'<%= helpers.asset_path "application.css" %>',
'<%= helpers.asset_path "mobile.css" %>',
'/icons/icon-white-24x24.png',
'/icons/icon-24x24.png',
'/icons/icon-96x96.png',
'/apple-touch-icon.png',
'/offline-notice.html'
]);
})
);
}
function onActivate(event) {
console.log('[Serviceworker]', "Activating!", event);
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.filter(function(cacheName) {
// Return true if you want to remove this cache,
// but remember that caches are shared across
// the whole origin
return cacheName.indexOf(CACHE_VERSION) !== 0;
}).map(function(cacheName) {
return caches.delete(cacheName);
})
);
})
);
}
// Borrowed from https://github.com/TalAter/UpUp
function onFetch(event) {
event.respondWith(
// try to return untouched request from network first
fetch(event.request).catch(function() {
// if it fails, try to return request from the cache
return caches.match(event.request).then(function(response) {
if (response) {
return response;
}
// if not found in cache, return default offline content for navigate requests
if (event.request.mode === 'navigate' ||
(event.request.method === 'GET' && event.request.headers.get('accept').includes('text/html'))) {
console.log('[Serviceworker]', "Fetching offline content", event);
return caches.match('/offline-notice.html');
}
})
})
);
}
self.addEventListener("push", function (event) {
var title = event.data.json()['title'];
var body = event.data.json()['body'];
var tag = event.data.json()['tag'] || '';
var icon = event.data.json()['icon'] || '';
var sound = event.data.json()['sound'] || '';
var image = event.data.json()['image'] || '';
var actions = event.data.json()['actions'] || [];
var badge = '/icons/icon-white-24x24.png';
var data = event.data.json()['data'] || {};
event.waitUntil(self.registration.showNotification(title, {
body: body,
icon: icon,
badge: badge,
sound: sound,
image: image,
actions: actions,
data: data,
vibrate: [500,110,500,110,450,110,200,110,170,40,450,110,200,110,170,40,500],
tag: tag
}));
});
self.addEventListener('notificationclick', function(event) {
console.log('[Nobi] Notification click Received.');
event.waitUntil(
clients.openWindow(event.notification.data['link'])
);
});
self.addEventListener('install', onInstall);
self.addEventListener('activate', onActivate);
self.addEventListener('fetch', onFetch);
The webpack-dev-server is running fine, it's only when deploying to production this is giving issues.
In case it helps someone else having this issue, it was happening to me when trying to deploy to heroku using ../bin/rails runner
for the runner
option. Along the lines of the suggestion in #63 (comment) changing it to ../bin/bundle exec rails runner
fixed the issue.
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 assets:precompile
step. None of the solutions I found here or elsewhere solved the problem.
Ultimately, I discovered that my binstubs were not executable upon deploy. #fml
This was the error I was getting.
remote: events.js:174
remote: throw er; // Unhandled 'error' event
remote: ^
remote:
remote: Error: spawn bin/rails EACCES
remote: at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
remote: at onErrorNT (internal/child_process.js:415:16)
remote: at process._tickCallback (internal/process/next_tick.js:63:19)
remote: Emitted 'error' event at:
remote: at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
remote: at onErrorNT (internal/child_process.js:415:16)
remote: at process._tickCallback (internal/process/next_tick.js:63:19)
remote:
remote: The command '/bin/sh -c bundle exec rails assets:precompile' returned a non-zero code: 1
Maybe add console.log
here: https://github.com/usabilityhub/rails-erb-loader/blob/master/index.js#L93
child.stdout.on('data', function (data) {
console.log(data);
dataBuffers.push(data);
})
Would be good to have options: { debug: true }
that turns on verbose logging like printing dataBuffers
.
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 <%= icon("icons8-marker-48.png") %>
in maps.js.erb
ruby '2.7.0'
gem 'rails', '~> 6.0.3', '>= 6.0.3.2'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 4.1'
gem 'jbuilder', '~> 2.7'
gem 'webpacker'
gem 'bootsnap', '>= 1.4.2', require: false
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
And
yarn add @rails/webpacker
rails webpacker:install
yarn add rails-erb-loader
yarn add ol // openlayers which is what the tutorial is about
Error in localhost:
bootstrap:83 Uncaught Error: Module build failed (from /Users/gscar/node_modules/rails-erb-loader/index.js):
Error: rails-erb-loader failed with code: 1
at ChildProcess.<anonymous> (:3000/Users/gscar/node_modules/rails-erb-loader/index.js:128)
at ChildProcess.emit (:3000/events.js:314)
at maybeClose (:3000/internal/child_process.js:1047)
at Socket.<anonymous> (:3000/internal/child_process.js:438)
at Socket.emit (:3000/events.js:314)
at Pipe.<anonymous> (:3000/net.js:672)
at Object../app/javascript/packs/maps.js.erb (bootstrap:83)
at __webpack_require__ (bootstrap:19)
at bootstrap:83
at bootstrap:83
./app/javascript/packs/maps.js.erb @ bootstrap:83
__webpack_require__ @ bootstrap:19
(anonymous) @ bootstrap:83
(anonymous) @ bootstrap:83
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 webpack.config.js
in my project. I realize Rails handles these things differently but it's more to wade through. And Rails guides hasn't caught up.
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.
Not sure about your first sentence. The error I showed is the only error in Chrome Console.
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.
Many recommended against handling images with Webpacker
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 require
images with webpack itself though, just don't use this module for it. rails-erb-loader is very slow and error-prone, and needlessly heavy handed for that task. Furthermore ERB prevents your JS from being statically analysed by linters, prettier and other code tools.
Part of it is the changing recommendations and to start with I don't have a webpack.config.js in my project.
My guess is that webpacker would be set up to handle images via image-loader
(it's a built-in package). Try require()
ing an image path from your source folder and it should work. I've never had a project that doesn't require modification of the webpack config, might want to look into how to get access to it π€·.
I get this error message when attempting to compile a .js.erb file with webpacker.
`ERROR in ./app/javascript/packs/freelancer.js.erb Module build failed (from ./node_modules/rails-erb-loader/index.js): Error: rails-erb-loader failed with code: 1
at ChildProcess.<anonymous> (/mnt/c/Code/helloworld/node_modules/rails-erb-loader/index.js:128:16)
at ChildProcess.emit (events.js:198:13)
at maybeClose (internal/child_process.js:982:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5) (erb):12:in
': undefined method render' for main:Object (NoMethodError) from /home/ben/.rbenv/versions/2.6.5/lib/ruby/2.6.0/erb.rb:901:in eval'
from /home/ben/.rbenv/versions/2.6.5/lib/ruby/2.6.0/erb.rb:901:in result' from /mnt/c/Code/helloworld/node_modules/rails-erb-loader/erb_transformer.rb:20:in '`
My erb.js file looks like this.
`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, }, }, }], }`
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
'Error: spawn DISABLE_SPRING=1 ENOENT erb-rails-loader'.
I've tried adding
'options: { runner: 'DISABLE_SPRING=1 bin/rails runner' }'
same ENOENT error.
I've tried adding the below snippet to erb.js, same exit code: 1
engine: { name: 'erubis', includes: [ 'ActionView::Helpers', 'Rails.application.routes.url_helpers' ] }
I've also tried adding the helper in my transformer_erb file like such
require 'erb' include Rails.application.routes.url_helpers ERB
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.
$('#records_table').append("<%= j(render 'partials/gallery_items')%>"); $('#div_next_link').html("<%= j(render 'partials/next_link') %>");
I'm commenting on #63 (comment) but it should be a starter for anyone who has issues with rails-erb
:
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.
It's not a conflict but the thing is : rails-erb-loader calls the rails runner
command (https://guides.rubyonrails.org/command_line.html#rails-runner) to generate JS from js.erb
templates.
What it says:
runner runs Ruby code in the context of Rails non-interactively
So your app must be fully functionnal before calling rake assets:precompile
in any environment.
To be sure: run your app locally but in production
mode (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:precompile
will surely fail later.
It also means that your view.js.erb
file must contain valid Ruby/Rails code or it will fail too.
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
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 :)
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 render
which 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 render
at 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 using render
and partial
, 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).
@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 Error: rails-erb-loader failed with code: 1
higher up in my logs, it was the Zeitwork
error further down that was the root of the issue. In my case, I needed to rename/remove compiled directory names beginning with a number to make Zeitwork
happy, which was pretty explicit in the error logging...!
ALSO, for anyone coming here on a ModuleNotFoundError
on their rails-erb-loader
, check your package.json
!! Following the instructions in the rails-erb-loader
Readme will have you adding the module in your devDependencies
which is invisible to your production env :(
For a good time, add rails-erb-loader
as a standard dependency, not a devDependency.
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 erb_transformer.rb
file and see if it prints your error.
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 ruby 3.0.1
and rails 6.1.3.2
that kept failing only on Travis.
After a lot of debugging I found that my error was FATAL: Listen error: unable to monitor directories for changes
so after adding this to my travis.yml
my assets:precompile started working again π
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 DISABLE_SPRING=1
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...
/app/app/node_modules/rails-erb-loader/erb_transformer.rb:13:in `<top (required)>': Unknown templating engine `__RAILS_ERB_LOADER_DELIMETER__` (RuntimeError)
It seems the process is receiving the following ARGV, which is logically incorrect per erb_transformer.rb
["/app/node_modules/rails-erb-loader/erb_transformer.rb", "__RAILS_ERB_LOADER_DELIMETER__", "erb"]
I think this is due to the eager loading that happens on production, for some reason app/node_modules
is an eager loaded path and when it tries to load the erb_transformer.rb
file, it blows up ...
@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.
So your app must be fully functionnal before calling rake assets:precompile in any environment.
On dev environment the erb-loader was working fine. The issue would appear only when deploying to Heroku review apps. The logs would show
Module build failed: Error: rails-erb-loader failed with code: 1
for all .js.erb
files, and further down there was also other database errors that seemed unrelated:
PG::UndefinedTable: ERROR: relation "xxx" does not exist (ActiveRecord::StatementInvalid)
After hours of debugging, we found out that bin/rails runner
was trying to load database dependencies when the db had no schema loaded yet. On Heroku review apps the assets:precompile
is executed on the build phase, while db:schema:load
is executed on post-deploy.
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!
After hours of debugging, we found out that bin/rails runner was trying to load database dependencies when the db had no schema loaded yet.
So this module will just do whatever happens when you call rails runner
. If that depends on your schema then it'll have to be there. It's an unfortunate design choice of ActiveRecord that it reads your schema at startup, compounded with the unfortunate design of Rails loading up every single object at startup.
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.
The solution was to remove this gem and use asset pipeline setup for this specific use case π.
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 assets:precompile
and develop our app as an SPA using webpack. rails-erb-loader should be treated as a necessary evil to migrate a codebase away from Rails asset pipeline, not as a permanent part of your stack. It's not particularly good, but it'll save you migrating your old erb
files over in one go. There are better options available for templating your front end dependencies that do not require Rails at all. The simplest of these is simply storing your shared constants in a JSON file that is read by both json-loader and Rails itself at startup.
I tryied same error.
I got this error message. I think that "runner_command.rb:46" can not find a file (or not exist). The erb_transformer.rb file path is under ".yarn/__virtual__/". Why rails-erb-loader can not find the file?
I created repro this Dockerfile.zip.
not found filename
/web/.yarn/__virtual__/rails-erb-loader-virtual-27b0bedac7/0/cache/rails-erb-loader-npm-5.5.2-8c1ad94c6e-f89ac4f14b.zip/node_modules/rails-erb-loader/erb_transformer.rb
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
- ruby: 3.1.2
- webpack: 5.72.1
- yarn: 3.2.1
- rails: 7.0
Per @rhys-vdw's comment
I ran into an issue that exemplifies the following statement given by @n-rodriguez, and wanted to highlight it.
So your app must be fully functionnal before calling rake assets:precompile in any environment.
On dev environment the erb-loader was working fine. The issue would appear only when deploying to Heroku review apps. The logs would show
Module build failed: Error: rails-erb-loader failed with code: 1
for all
.js.erb
files, and further down there was also other database errors that seemed unrelated:PG::UndefinedTable: ERROR: relation "xxx" does not exist (ActiveRecord::StatementInvalid)
After hours of debugging, we found out that
bin/rails runner
was trying to load database dependencies when the db had no schema loaded yet. On Heroku review apps theassets:precompile
is executed on the build phase, whiledb:schema:load
is executed on post-deploy.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!
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:
./lib/tasks/heroku_review_app_assets_precompile.rake
if ENV["RAILS_ENV"] == "review"
Rake::Task["assets:precompile"].enhance(["db:schema:load"])
end
It does mean that rails db:schema:load
happens twice, but seems like only a nit? Or maybe this is too naive?