Webpacker: bundler: failed to load command: webpack

Created on 22 Feb 2018  ·  6Comments  ·  Source: rails/webpacker

Hi, I am following the installation instructions and when I attempt to deploy to Heroku, I see this:

remote:        Running: rake assets:precompile
remote:        I, [2018-02-22T05:05:54.811401 #412]  INFO -- : Writing /tmp/build_7ffe41733c668d5375f4c7e16f34a7c9/public/assets/subscribe-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.js
remote:        I, [2018-02-22T05:05:54.813303 #412]  INFO -- : Writing /tmp/build_7ffe41733c668d5375f4c7e16f34a7c9/public/assets/subscribe-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.js.gz
remote:        Webpacker is installed 🎉 🍰
remote:        Using /tmp/build_7ffe41733c668d5375f4c7e16f34a7c9/config/webpacker.yml file for setting up webpack paths
remote:        Compiling…
remote:        Compilation failed:
remote:        bundler: failed to load command: webpack (/tmp/build_7ffe41733c668d5375f4c7e16f34a7c9/vendor/bundle/ruby/2.2.0/bin/webpack)
remote:        The latest bundler is 1.16.1, but you are currently running 1.15.2.
remote:        To update, run `gem install bundler`
remote:        Errno::ENOENT: No such file or directory - /tmp/build_7ffe41733c668d5375f4c7e16f34a7c9/node_modules/.bin/webpack
remote:        /tmp/build_7ffe41733c668d5375f4c7e16f34a7c9/vendor/bundle/ruby/2.2.0/gems/webpacker-3.2.2/lib/webpacker/webpack_runner.rb:11:in `exec'
remote:        /tmp/build_7ffe41733c668d5375f4c7e16f34a7c9/vendor/bundle/ruby/2.2.0/gems/webpacker-3.2.2/lib/webpacker/webpack_runner.rb:11:in `block in run'
remote:        /tmp/build_7ffe41733c668d5375f4c7e16f34a7c9/vendor/bundle/ruby/2.2.0/gems/webpacker-3.2.2/lib/webpacker/webpack_runner.rb:10:in `chdir'
remote:        /tmp/build_7ffe41733c668d5375f4c7e16f34a7c9/vendor/bundle/ruby/2.2.0/gems/webpacker-3.2.2/lib/webpacker/webpack_runner.rb:10:in `run'
remote:        /tmp/build_7ffe41733c668d5375f4c7e16f34a7c9/vendor/bundle/ruby/2.2.0/gems/webpacker-3.2.2/lib/webpacker/runner.rb:6:in `run'
remote:        /tmp/build_7ffe41733c668d5375f4c7e16f34a7c9/vendor/bundle/ruby/2.2.0/gems/webpacker-3.2.2/exe/webpack:8:in `<top (required)>'
remote:        /tmp/build_7ffe41733c668d5375f4c7e16f34a7c9/vendor/bundle/ruby/2.2.0/bin/webpack:23:in `load'
remote:        /tmp/build_7ffe41733c668d5375f4c7e16f34a7c9/vendor/bundle/ruby/2.2.0/bin/webpack:23:in `<top (required)>'
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed

I've ensured that NODE_ENV=production is set correctly on Heroku as well. Would love to know if I have missed something. Not a very complex rails app. Thank you.

Most helpful comment

It was the order of my build packs. I had to add heroku buildpacks:add nodejs -i 1 and the deploy worked. I will open a pull request adding this to the docs for others in the future. What a headache.

All 6 comments

When I run NODE_ENV=production RAILS_ENV=production rails assets:precompile --trace locally the command completes successfully.

I have also added

  "engines": {
      "node": ">=6.0.0",
      "yarn": ">0.25.2"
  }

to my packages.json as per #821 as well as ensured both node and ruby build packs are on my app, with the same result.

Here is my webpacker.yml:

# Note: You must restart bin/webpack-dev-server for changes to take effect

default: &default
  source_path: app/javascript
  source_entry_path: packs
  public_output_path: packs
  cache_path: tmp/cache/webpacker

  # Additional paths webpack should lookup modules
  # ['app/assets', 'engine/foo/app/assets']
  resolved_paths: []

  # Reload manifest.json on all requests so we reload latest compiled packs
  cache_manifest: false

  extensions:
    - .js
    - .sass
    - .scss
    - .css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

development:
  <<: *default
  compile: true

  # Reference: https://webpack.js.org/configuration/dev-server/
  dev_server:
    https: false
    host: localhost
    port: 3035
    public: localhost:3035
    hmr: false
    # Inline should be set to true if using HMR
    inline: true
    overlay: true
    compress: true
    disable_host_check: true
    use_local_ip: false
    quiet: false
    headers:
      'Access-Control-Allow-Origin': '*'
    watch_options:
      ignored: /node_modules/


test:
  <<: *default
  compile: true

  # Compile test packs to a separate directory
  public_output_path: packs-test

production:
  <<: *default

  # Production depends on precompilation of packs prior to booting for performance.
  compile: false

  # Cache manifest.json for performance
  cache_manifest: true

It was the order of my build packs. I had to add heroku buildpacks:add nodejs -i 1 and the deploy worked. I will open a pull request adding this to the docs for others in the future. What a headache.

full command that fixed it (for anyone else that ends up here)

heroku buildpacks:add heroku/nodejs -i 1 --app $HEROKU_APP_NAME
heroku buildpacks:add heroku/ruby -i 2 --app  $HEROKU_APP_NAME
Was this page helpful?
0 / 5 - 0 ratings