usabilityhub / rails-erb-loader

Embedded Ruby (.erb) webpack loader for Ruby projects.
MIT License
103 stars 28 forks source link

Error: rails-erb-loader failed with code: 1 #63

Open Swat123 opened 6 years ago

Swat123 commented 6 years ago

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"
}
rhys-vdw commented 6 years ago

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 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.

Swat123 commented 6 years ago

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 ?

rhys-vdw commented 6 years ago

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...

  1. Improve the error message to include the actual executable that returned the error code (see my previous comment)
  2. 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.
  3. 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.
  4. 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. :)

rhys-vdw commented 6 years ago

I wonder if we can learn something from the spring server command...

dreyks commented 6 years ago

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

rhys-vdw commented 6 years ago

@dreyks oh dear!

kofronpi commented 6 years ago

I'm also affected by this with undecipherable errors. I will investigate and report back.

rhys-vdw commented 6 years ago

Thanks @kofronpi. It's hard for me to investigate because I am not experiencing this issue at the moment.

akaspick commented 6 years ago

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.

akaspick commented 6 years ago

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.

rhys-vdw commented 6 years ago

@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, otherwise null. If the process terminated due to receipt of a signal, signal is the string name of the signal, otherwise null. 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?

akaspick commented 6 years ago

@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.

rhys-vdw commented 6 years ago

@akaspick no problem, see #65.

rhys-vdw commented 6 years ago

@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.

n-rodriguez commented 6 years ago

Setting NODE_ENV might save you : https://github.com/rails/webpacker/issues/1374

n-rodriguez commented 6 years ago

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 :)

rhys-vdw commented 6 years ago

@n-rodriguez so this is an issue with webpacker, not not rails-erb-loader?

n-rodriguez commented 6 years ago

@n-rodriguez so this is an issue with webpacker, not not rails-erb-loader?

well it seems to be...

n-rodriguez commented 6 years ago

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.

rhys-vdw commented 6 years ago

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.

andybluey commented 6 years ago

@n-rodriguez - can you please let me know the change you made? Thanks

n-rodriguez commented 6 years ago

Setting NODE_ENV env var saved my day :)

dmke commented 6 years ago

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...

rhys-vdw commented 6 years ago

@dmke FYI current version of rails-erb-loader has a bug that prevents setting env vars that way. See #64. You'll need to set them in the parent environment.

andybluey commented 6 years ago

Hey @n-rodriguez - sorry, just to confirm, where and how did you add NODE_ENV env var? Thnks

n-rodriguez commented 6 years ago

@andybluey I use Dotenv gem

dmke commented 6 years ago

@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 :-))

rhys-vdw commented 6 years ago

@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.

rhys-vdw commented 6 years ago

@andybluey

FYI you can always do this:

$ NODE_ENV=development npm run dev

Where dev is your dev server "script".

luislezcair commented 6 years ago

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.

bbugh commented 6 years ago

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.

rhys-vdw commented 6 years ago

@luislezcair

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?

rhys-vdw commented 6 years ago

@bbugh this sounds unrelated. Are you compiling any erb files?

rhys-vdw commented 6 years ago

@bbugh also, is there any way of getting a full stack trace?

bbugh commented 6 years ago

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 ```bash /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 `' 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 `' from /home/circleci/circleci-demo-ruby-rails/vendor/bundle/gems/spring-2.0.2/lib/spring/commands.rb:4:in `' 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 `' 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 `
' 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. (/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 ```
luislezcair commented 6 years ago

@rhys-vdw Yes, the repo I uploaded reproduces the issue when deploying to Heroku. It works fine locally.

rhys-vdw commented 6 years ago

@luislezcair did you notice that you have some ERB in a comment? Any chance that's an issue?

rhys-vdw commented 6 years ago

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.

rhys-vdw commented 6 years ago

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.

luislezcair commented 6 years ago

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.

rhys-vdw commented 6 years ago

@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
rhys-vdw commented 6 years ago

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.

dreyks commented 6 years ago

you're getting Stack level to deep. which means you probably have an infinite recursive method call

luislezcair commented 6 years ago

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)> 
dreyks commented 6 years ago

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

rhys-vdw commented 6 years ago

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.

rhys-vdw commented 6 years ago

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.

rkotov93 commented 6 years ago

Hey @bbugh, I've got stuck with the same issue on CircleCI, did you find the way to resolve it?

bbugh commented 6 years ago

@rkotov93 sorry no, we ended up removing it because of the instability. We ended up using environment variables to pass data.

prithvi16 commented 5 years ago

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. https://github.com/rails/spring/pull/546