15

I created my rails with this template that included webpack, I still write my javascript code in app/assets/javascript. I am trying to deploy my app to heroku and it keeps failing, I get this error

"remote:
/tmp/build_6f0656280cbbda40c5832ccb79fc1783/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)"

I have tried lots of solutions but still cant get my app deployed to Heroku. I want to know how to completely delete webpack and all its depencies from my app since it was not even useful to my app

    source 'https://rubygems.org'
ruby '2.3.5'

gem 'figaro'
gem 'jbuilder', '~> 2.0'
gem 'puma'
gem 'rails', '5.1.4'
gem 'redis'
gem 'cloudinary'
gem 'carrierwave', '~> 1.2'
gem 'rails_admin', '~> 1.2'
group :production do
 gem 'pg', '~> 0.20'
end



gem 'autoprefixer-rails'
gem 'bootstrap-sass'
gem 'jquery-rails'
gem 'font-awesome-sass'
gem 'sass-rails'
gem 'simple_form'
gem 'turbolinks', '~> 5.0.0'
gem 'coffee-rails'

gem 'uglifier'
gem 'webpacker'
gem 'devise'
gem 'ransack'
gem 'trix'


gem "letter_opener", group: :development


group :development do
  gem 'web-console', '>= 3.3.0'
  gem 'sqlite3'
end

group :development, :test do
  # gem 'binding_of_caller'
  # gem 'better_errors'
  gem 'pry-byebug'
  gem 'pry-rails'
  gem 'listen', '~> 3.0.5'
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end
Ben
  • 5,030
  • 6
  • 53
  • 94
Hakeem Baba
  • 647
  • 1
  • 12
  • 32
  • How is your `bin` path looking like? Do you have a `webpage` executable there? Might also be worth trying to do `bundle clean` – alexdotsh Mar 05 '18 at 10:49

1 Answers1

28
  • remove bin/webpackor run bundle exec rake rails:update:bin
  • remove config/webpacker.yml
  • remove config/webpack
  • remove app/javascripts
  • remove config.webpacker.check_yarn_integrity = false from config/{development, test, production}.rb
  • verify that you don't have webpacker in your gemfile and run bundle install or bundle clean

imho, don't create your rails app with generators (unless it's your own)

Ben
  • 5,030
  • 6
  • 53
  • 94
  • 1
    My rails application did not include a '.bin/webpack' file. Instead, I deleted './bin/webpack'. – Jacob Lockard May 11 '20 at 20:19
  • 7
    You also have to change '<%= javascript_pack_tag :application %>' to '<%= javascript_include_tag :application %>' in your `application.html.erb`. – Liz Aug 25 '21 at 20:38
  • 2
    ...and add `config.assets.check_precompiled_asset = false` in your `config/environments/development.rb`. – Liz Aug 25 '21 at 20:41
  • 3
    ...and add `Rails.application.config.assets.precompile += %w( application.js )` to your `config/initializers/assets.rb` or it will fail in production. – Liz Aug 25 '21 at 20:55
  • After following along, I get an "Uncaught ReferenceError: jQuery is not defined" error in production, but not in development or test.Also, there is missing javascript functionality in production that is not missing in development. I am guessing somehow I'm not loading JQuery. But I am getting an "app...js" file in production, and it doesn't look "tiny". Is there a step by step way to see what is included in the javascript bundle and from where. Also, what's the easiest way to have the same behavior in development, can't really futz with production. (Sorry, it's been a while.) – codenoob Feb 05 '22 at 21:14
  • @codenoob it is obvious. if you have webpacker anymore, you can't rely on what you required in package.json. then you need to import your js libraries via the standard assets pipeline, or by calling those scripts with standard tags in your layout – Ben Feb 06 '22 at 09:48
  • You also need to comment `Rails.application.config.assets.paths << Rails.root.join('node_modules')` in your `config/initializers/assets.rb`. – Fernando Kosh Aug 31 '23 at 00:17