Asset precompilation in production: Including ./vendor/assets

Hello everyone,

I’m struggling with precompiling assets both on Heroku and locally when the environment is set to production.

I have a manifest file, ./app/assets/javascripts/application.js which includes another file, located at ./vendor/assets/javascripts/fullcalendar/dist/fullcalendar.js as follows:

//= require fullcalendar/dist/fullcalendar

This works just fine when I run a local server in development mode. I noticed something is off when I pushed to Heroku, which won’t precompile my assets:

remote: Running: rake assets:precompile

remote: rake aborted!

remote: Sprockets::FileNotFound: couldn’t find file ‘fullcalendar/dist/fullcalendar’ with type ‘application/javascript’

So I tried precompiling assets locally, which works as expected when the environment is set to development. However, when I run …

% RAILS_ENV=production bundle exec rake assets:precompile --trace

… ExecJS yells at me (full trace here):

** Execute assets:precompile

rake aborted!

ExecJS::ProgramError: Unexpected token punc «(», expected punc «:» (line: 70927, col: 13, pos: 2134177)

I have no idea what’s wrong or how to debug this, because all of my own JavaScript gets tested, linted and passes just fine. My application doesn’t throw errors in browsers either. I assume one of my dependencies uses ES6 method definitions?

Those are my asset paths:

./app/assets/images ./app/assets/javascripts ./app/assets/stylesheets ./vendor/assets/bower_components ./vendor/assets/javascripts ./vendor/assets/stylesheets

And the only change I made in ./config/initializers/assets.rb is adding another manifest file for precompilation:

Rails.application.config.assets.precompile += %w(onboarding.js)

So to sum up my two questions:

  • How do I properly include files located at /vendor/assets/**/* in manifest files?
  • What’s ExecJS executing at precompilation and how do I figure what breaks it?

Thanks in advance!

Hello everyone,

I’m struggling with precompiling assets both on Heroku and locally when the environment is set to production.

It is worth, if you have not already done so, running the app and in the browser check the javascript console to make sure it does not see any problems.

Do you have any dynamic stuff in your javascript that might be picking up from ENV with different results in different environments?

Colin

Hi Colin, thanks for your reply.

I’ve already checked the console for error messages and my tests pass.

I disabled JavaScript compression in production so that ExecJS is no longer run (in config/environments/production.rb):

config.assets.js_compressor = :uglifier

I can now precompile my assets locally, even with RAILS_ENV set to production.

But I still get the exact same error when pushing to Heroku …