When trying to deploy a rails 5 app to heroku, I get the following error, when it reaches Running: rake assets:precompile
:
remote: ExecJS
As the Uglifier official documentation says (https://github.com/lautis/uglifier):
"The experimental ES6 syntax support can be enabled by passing :harmony => true option to Uglifier."
Uglifier.compile(js, harmony: true)
So replace in config/environments/production.rb
.
config.assets.js_compressor = :uglifier
with
config.assets.js_compressor = Uglifier.new(harmony: true)
I had this issue and it was throwing Uglifier::Error: Unexpected token: name (subscription)
It ended up being an actual syntax error.
I accidentally had left the words "cancel subscription" in one of my JS files and it was causing it to throw that error
In my case I am using angularjs-rails gem and some how used es6 standard so solve it by commenting uglifier compressor in file config/environments/production.rb.
#config.assets.js_compressor = :uglifier
Seems to be some issues with newer ES syntax. Backtick's also won't pre-compile.
my example:
http://localhost:3000//${bike_file}.html
I changed to
"http://localhost:3000//" + bike_file + ".html"
I also had this issue.
It's important to remember that by default Heroku is precompiling in a production environment. When you run rake assets:precompile
locally it's typically a development environment, which for me didn't exhibit the issue.
So in order to reproduce the issue locally, try
RAILS_ENV=production rake assets:precompile --trace
It may have something to do with javascript/coffescript syntax. Check if you have let
, it shout be replaced with var
.
Edit - see @Guilherme Lages Santos's response. Uglifier added ES6 support since version 3.2.0 so you can just use it like this in your environment file
config.assets.js_compressor = Uglifier.new(harmony: true)