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

Created on 22 Jun 2017  路  8Comments  路  Source: rails/webpacker

I get this error in production, while the app works perfectly in development.

From my Stack Overflow question:

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.

Full source for project is available at https://github.com/amingilani/planetlauncher

Most helpful comment

Ah, I figured it out. I had created my Rails app with --skip-sprockets since I wanted everything to be managed by Webpack without getting Sprockets involved. Heroku's Ruby buildpack, however, merely runs rake assets:precompile, which in turn will run the webpacker:compile task, but if you don't have Sprockets, you won't have the assets:precompile task, and so the buildpack will never end up running webpacker:compile.

I fixed this by going through the Rails source code, figuring out what needed to be added to my app to manually undo the --skip-sprockets option, making the changes necessary and pushing back to Heroku.

All 8 comments

I just noticed that /public/packs is in my .gitignore. This was generated by Rails using the rails new --webpack=react command.

Could this have something to do with this?

@amingilani Yes that's it - if you compile assets locally heroku won't precompile -

screen shot 2017-06-22 at 20 30 20

So either - remove it 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.

Yes! removing my assets precompiled fixed it! Thanks @gauravtiwari

Hey @gauravtiwari, I'm having a similar problem, but I don't have the option to delete /public/assets because that directory never gets generated locally. Looks like my manifest file is being generated but it's empty. Here's my error from Heroku's logs:

2017-12-28T04:14:20.372563+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4] Started GET "/" for 73.241.114.241 at 2017-12-28 04:14:20 +0000
2017-12-28T04:14:20.374311+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4] Processing by StaticPagesController#landing as HTML
2017-12-28T04:14:20.376213+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4]   Rendering static_pages/landing.html.erb within layouts/application
2017-12-28T04:14:20.376726+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4]   Rendered static_pages/landing.html.erb within layouts/application (0.4ms)
2017-12-28T04:14:20.384481+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4] Completed 500 Internal Server Error in 10ms
2017-12-28T04:14:20.385017+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4]
2017-12-28T04:14:20.385058+00:00 app[web.1]: 1. You want to set webpacker.yml value of compile to true for your environment
2017-12-28T04:14:20.385056+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4] ActionView::Template::Error (Webpacker can't find polyfills.js in /app/public/packs/manifest.json. Possible causes:
2017-12-28T04:14:20.385060+00:00 app[web.1]: 2. Webpack has not yet re-run to reflect updates.
2017-12-28T04:14:20.385059+00:00 app[web.1]:    unless you are using the `webpack -w` or the webpack-dev-server.
2017-12-28T04:14:20.385061+00:00 app[web.1]: 4. Your Webpack configuration is not creating a manifest.
2017-12-28T04:14:20.385060+00:00 app[web.1]: 3. You have misconfigured Webpacker's config/webpacker.yml file.
2017-12-28T04:14:20.385061+00:00 app[web.1]: Your manifest contains:
2017-12-28T04:14:20.385062+00:00 app[web.1]: {
2017-12-28T04:14:20.385063+00:00 app[web.1]: }
2017-12-28T04:14:20.385063+00:00 app[web.1]: ):
2017-12-28T04:14:20.385200+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4]     50:         margin: 0.6em 0;
2017-12-28T04:14:20.385201+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4]     51:       }
2017-12-28T04:14:20.385201+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4]     52:     </style>
2017-12-28T04:14:20.385202+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4]     53:     <%= javascript_pack_tag 'polyfills' %>
2017-12-28T04:14:20.385203+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4]     54:     <%= javascript_pack_tag 'application' %>
2017-12-28T04:14:20.385204+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4]     56:
2017-12-28T04:14:20.385207+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4]
2017-12-28T04:14:20.385203+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4]     55:   </head>
2017-12-28T04:14:20.385237+00:00 app[web.1]: [c1c1383e-aabf-4321-9d14-5634976b51e4] app/views/layouts/application.html.erb:53:in `_app_views_layouts_application_html_erb__4311322416971945423_27503820'

Also, from the build log, I notice that I don't get the Detected manifest file, assuming assets were compiled locally warning. Relevant part:

remote: -----> Installing node-v6.11.1-linux-x64
remote: -----> Installing yarn-v1.0.2
remote: -----> Detecting rake tasks
remote:
remote: -----> Discovering process types
remote:        Procfile declares types     -> web
remote:        Default types for buildpack -> console, rake, worker
remote:
remote: -----> Compressing...
remote:        Done: 37M
remote: -----> Launching...

Any ideas?

Ah, I figured it out. I had created my Rails app with --skip-sprockets since I wanted everything to be managed by Webpack without getting Sprockets involved. Heroku's Ruby buildpack, however, merely runs rake assets:precompile, which in turn will run the webpacker:compile task, but if you don't have Sprockets, you won't have the assets:precompile task, and so the buildpack will never end up running webpacker:compile.

I fixed this by going through the Rails source code, figuring out what needed to be added to my app to manually undo the --skip-sprockets option, making the changes necessary and pushing back to Heroku.

@gauravtiwari

Thanks for taking the time to reply to so many comments.

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.

I've just started using Webpacker but as far as I can tell the precompile should work locally also. Is there any reason you recommend leaving it to Heroku and not doing it locally?

Reference:

Webpacker hooks up a new webpacker:compile task to assets:precompile, which gets run whenever you run assets:precompile. If you are not using Sprockets webpacker:compile is automatically aliased to assets:precompile. Remember to set NODE_ENV environment variable to production during deployment or when running the rake task.

https://github.com/rails/webpacker/blob/master/docs/deployment.md#deployment

Was this page helpful?
0 / 5 - 0 ratings

Related issues

suhomozgy-andrey picture suhomozgy-andrey  路  3Comments

FrankFang picture FrankFang  路  3Comments

christianrojas picture christianrojas  路  3Comments

towry picture towry  路  3Comments

ankitrg picture ankitrg  路  3Comments