Amin Shah Gilani
Amin Shah Gilani

Reputation: 9886

ActionView::Template::Error (Can't find sales.js in /app/public/packs/manifest.json. Is webpack still compiling?)

I get this error on my Rails 5.1.1 app that I just hosted on Heroku

2017-06-22T05:15:05.148829+00:00 app[web.1]: F, [2017-06-22T05:15:05.148717 #4] FATAL -- : [ef509b29-8637-41b3-8224-4423dbf2b2ed]
2017-06-22T05:15:05.148948+00:00 app[web.1]: F, [2017-06-22T05:15:05.148883 #4] FATAL -- : [ef509b29-8637-41b3-8224-4423dbf2b2ed] ActionView::Template::Error (Can't find sales.js in /app/public/packs/manifest.json. Is webpack still compiling?):
2017-06-22T05:15:05.149203+00:00 app[web.1]: F, [2017-06-22T05:15:05.149103 #4] FATAL -- : [ef509b29-8637-41b3-8224-4423dbf2b2ed]     1: %div#sale
2017-06-22T05:15:05.149206+00:00 app[web.1]: [ef509b29-8637-41b3-8224-4423dbf2b2ed]     2: = javascript_pack_tag 'sales'
2017-06-22T05:15:05.149297+00:00 app[web.1]: F, [2017-06-22T05:15:05.149231 #4] FATAL -- : [ef509b29-8637-41b3-8224-4423dbf2b2ed]
2017-06-22T05:15:05.149398+00:00 app[web.1]: F, [2017-06-22T05:15:05.149328 #4] FATAL -- : [ef509b29-8637-41b3-8224-4423dbf2b2ed] app/views/sales/new.html.haml:2:in `_app_views_sales_new_html_haml___2340659139987297731_36903000'
2017-06-22T05:15:07.004434+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=planetlauncher.herokuapp.com request_id=8bca0b65-0d4a-494f-88c7-a4b31c2ff6dc fwd="202.163.79.6" dyno=web.1 connect=1ms service=2ms status=200 bytes=143 protocol=https

There's only one route

Rails.application.routes.draw do
  root 'sales#new'
  resources :sales
end

My app has a single view:

# sales/new.html.haml
%div#sale
= javascript_pack_tag 'sales'

The view is replaced by a React component at app/javascript/packs/sales.jsx on load.

The app works flawlessly in development, I ran rails assets:precompile before pushing, and deployed to Heroku.

Edit: Full source is available here

Upvotes: 1

Views: 846

Answers (1)

Amin Shah Gilani
Amin Shah Gilani

Reputation: 9886

According this @gauravtiwari from this github thread:

So either - remove [ the /public/packs line] from gitignore or don't precompile locally and let heroku do it i.e. delete the public/assets folder

BTW there is one gotcha - webpacker:compile depends on assets:precompile so best is to leave it to Heroku and don't compile assets locally.

So following his advice, I git revert my commits that precompiled assets locally and everything starte working.

You can either do what I did or run rm -rf /public/assets to get rid of your precompiled assets.

I suppose you can go one step further and add /public/assets to your .gitignore to ensure no one accidentally compiles assets in the future.

I'm leaving this question up because I got this weirdness from a vanilla rails app, someone else is bound to run into and upvote my answer since it helped them ;)

Upvotes: 1

Related Questions