Webpacker: Heroku: can't find executable webpack for gem webpacker (Gem::Exception)

Created on 5 Mar 2018  Â·  28Comments  Â·  Source: rails/webpacker

After upgrading to the master branch of this repository, I get the following error when compiling on Heroku:

       Compiling…
       Compilation failed:
       /tmp/build_d4da645e5840bc32169cdef3aecaed44/jonhue-jonhue-97c0597/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/rubygems_integration.rb:432:in `block in replace_bin_path': can't find executable webpack for gem webpacker (Gem::Exception)
       from /tmp/build_d4da645e5840bc32169cdef3aecaed44/jonhue-jonhue-97c0597/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/rubygems_integration.rb:463:in `block in replace_bin_path'
       from ./bin/webpack:29:in `<main>'
 !
 !     Precompiling assets failed.

Most helpful comment

Please run bundle exec rails webpacker:binstubs and commit binstubs to heroku.

All 28 comments

We are also seeing this without Heroku:

rails assets:precompile
...
/usr/local/lib/ruby/gems/2.4/gems/bundler-1.16.1/lib/bundler/rubygems_integration.rb:458:in `block in replace_bin_path': can't find executable webpack for gem webpacker (Gem::Exception)
        from /usr/local/lib/ruby/gems/2.4/gems/bundler-1.16.1/lib/bundler/rubygems_integration.rb:489:in `block in replace_bin_path'
        from ./bin/webpack:17:in `<main>'

I notice the FreeBSD package, rubygem-webpacker-rails5 starting with version 3.3.0 no longer installs bin/webpacker and bin/bin/webpack-dev-server under $PREFIX.

Please run bundle exec rails webpacker:binstubs and commit binstubs to heroku.

I had the same issue as well when upgrading to webpacker 3.3.0. You need regenerate the binstubs for webpacker (and webpack-dev-server if you are using hot reloading in development).

Thanks. Could you elaborate on what command need to be run to fix our rubygem-webpacker-rails5 package on FreeBSD (no Heroku)? I assume we need to run something to generate those two executable scripts that are now missing.

@gauravtiwari I did re-generate the binstubs using the :install generator. Your solution worked though. Any chance, they're not generating the same files?

Sorry, I somehow missed bundle exec rails webpacker:binstubs. I will try that.

@jonhue :install may overwrite any custom config you might have previously added to your webpack config files but the binstubs generated are the same as far as I know.

Of course, I did not override the config files 😉

Is it possible to generate the scripts without bundler? Bundler is not listed as a production dependency.

You could generate the binstubs in development and commit it to your repo before deploying.

This is for an OS package. Running bundler during the package build causes problems. Assuming the old behaviour of installing these scripts under $PREFIX/bin cannot be restored, is there a solution without bundler? What about simply creating links from ${PREFIX}/lib/ruby/gems/2.4/gems/webpacker-3.3.0/lib/install/bin/webpack to ${PREFIX}/bin ?

When I say creating links, I mean we would do this when building our package. Do you foresee any problems doing this?

Sorry for the noise. Basically what was suggested above works. We just have to run rails webpacker:binstubs in all packages that require webpacker. Thanks. :)

Same for AWS Elastic Beanstalk , after upgrading webpacker from 3.2.x to 3.3.x you have to update binstubs with bundle exec rails webpacker:binstubs

UPDATE: opps, it's actually written in the CHANGELOG.

Actually running this issue in my project. Got one app working in production but i'm unable to push another app with the same code and configuration (staging app, in heroku pipelines).
I tried running bundle exec rails webpacker:binstubs. Files webpack and webpack-dev-server are identicals.
Any idea/ suggestions ?
(Rails 5.1.4, Webpacker 3.3.0)

@AlexandrePerdomo Are you sure you are installing latest version of webpacker and npm package?

bundle update webpacker
yarn add @rails/webpacker

Are you able to compile locally?

Actually not understanding how i pushed my app 2 months ago with this configuration and not able to push my staging app today... Thx a lot for your help. Everything is working now.

Just wanted to add a comment saying that I got this error installing with rails new myapp --webpack (also with ... webpack=react). That was version 3.4.3.

None of the above fixes worked for me. I switched the webpacker version to 3.2.1 in my gemfile and that did it for me.

@eileennoonan83 Could you please share the error message you got? I tried to recreate but had no errors? Which command did you run to get the error?

@vishthemenon I got the same error message as is in the title of this issue, and I got it running both ‘rails new ...’ and when trying to install into an existing app

I should add I’m not using heroku, I was just starting a fresh project on my Mac

Unfortunately, I am not able to recreate the error. Are you able to run bin/webpack without error?

Am unable to run bin/webpack without errors ...

/home/ubuntu/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/bundler-1.16.1/lib/bundler/rubygems_integration.rb:458:in block in replace_bin_path': can't find executable webpack for gem webpacker (Gem::Exception) from /home/ubuntu/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/bundler-1.16.1/lib/bundler/rubygems_integration.rb:489:inblock in replace_bin_path'
from ./bin/webpack:17:in `

'

Any suggestions on what to fix?

Which version of rails, webpacker are u running? Have you tried regenerating your binstubs? That is often a common cause of this error especially when upgrading from 3.2+ to 3.3+

Rails 4.2.10
webpacker (4.0.0.pre.pre.2 1fce3a3)
Yes I have done bundle exec rake webpacker:install

Any other thoughts/suggestions on what I could be doing wrong?

Hmm, I tried recreating the error with the said versions but it seems to be working fine. Also do check if your node packages are updated as well.

Lastly, I did remember seeing a related issue linked to bundler version and the errors in binstubs generated by an older bundler version. Perhaps, upgrade your bundler and regenerate the binstubs. It should look something like this

#!/usr/bin/env ruby

ENV['RAILS_ENV'] ||= ENV['RACK_ENV'] || 'development'
ENV['NODE_ENV'] ||= ENV['RAILS_ENV']

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
                                           Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

require 'webpacker'
require 'webpacker/webpack_runner'
Webpacker::WebpackRunner.run(ARGV)

Why was a breaking change introduced in a minor version?

Was this page helpful?
0 / 5 - 0 ratings