uglifier: Uglifier::Error: Unexpected token: punc ((). To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true)
Hi,
When I run “rake assets:precompile RAILS_ENV=production” command, I have issue.
rake assets:precompile RAILS_ENV=production
rake aborted!
Uglifier::Error: Unexpected token: punc ((). To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true).
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/uglifier-4.0.2/lib/uglifier.rb:237:in parse_result' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/uglifier-4.0.2/lib/uglifier.rb:219:in run_uglifyjs’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/uglifier-4.0.2/lib/uglifier.rb:169:in compile' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/uglifier_compressor.rb:53:in call’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/uglifier_compressor.rb:28:in call' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:75:in call_processor’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:57:in block in call_processors' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in reverse_each’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in call_processors' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/loader.rb:134:in load_from_unloaded’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/loader.rb:60:in block in load' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/loader.rb:317:in fetch_asset_from_dependency_cache’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/loader.rb:44:in load' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:20:in block in initialize’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in load' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/base.rb:66:in find_asset’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/base.rb:73:in find_all_linked_assets' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:142:in block in find’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:114:in block (2 levels) in logical_paths' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:228:in block in stat_tree’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in block in stat_directory' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in each’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in stat_directory' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in stat_tree’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in each' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in block in logical_paths’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in each' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in logical_paths’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:140:in find' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:185:in compile’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in block (3 levels) in define' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-3.7.1/lib/rake/sprocketstask.rb:147:in with_logger’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in block (2 levels) in define' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/rake-12.2.1/exe/rake:27:in <top (required)>’
/Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/bin/ruby_executable_hooks:15:in eval' /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/bin/ruby_executable_hooks:15:in <main>’
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
How to fix this issue?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 42
- Comments: 31 (1 by maintainers)
Commits related to this issue
- Fix precompile bug https://github.com/lautis/uglifier/issues/127#issuecomment-352224986 — committed to Sinetheta/payment_request_api by Sinetheta 6 years ago
- Update config.assets.js_compressor per https://github.com/lautis/uglifier/issues/127. — committed to SplitTime/OpenSplitTime by moveson 6 years ago
- Modify config/environments/production.rb uglifier line due to errors (https://github.com/lautis/uglifier/issues/127) — committed to msarit/flixster by deleted user 6 years ago
- bugfix https://github.com/lautis/uglifier/issues/127#issuecomment-352224986 — committed to sizer/locateit by sizer 6 years ago
- update uglifier per https://github.com/lautis/uglifier/issues/127 — committed to mccollek/data-dictionary by mccollek 6 years ago
- uglifier stuff Uglifier.new(harmony: true) https://github.com/lautis/uglifier/issues/127#issuecomment-352224986 — committed to lucfranken/diy10 by lucfranken 6 years ago
- Uglifier with harmony (https://github.com/lautis/uglifier/issues/127) — committed to mirelon/prosody_analysis by deleted user 6 years ago
- config.assets.js_compressor = Uglifier.new(harmony: true) https://github.com/lautis/uglifier/issues/127 — committed to Koh0214/narou-susume by Koh0214 6 years ago
- fix: uglifier: https://github.com/lautis/uglifier/issues/127#issuecomment-352224986 — committed to cihad/teklifal by cihad 6 years ago
- jquery test 2 test 2 success. added "Uglifier.new(harmony: true)" to config/environment/production.rb See https://github.com/lautis/uglifier/issues/127 — committed to notoriousgorilla/HydroApp by notoriousgorilla 6 years ago
- changing uglifier settings to fix a build issue https://github.com/lautis/uglifier/issues/127 — committed to worknenjoy/truppie by alexanmtz 6 years ago
- changing uglifier settings to fix a build issue https://github.com/lautis/uglifier/issues/127 — committed to worknenjoy/truppie by alexanmtz 6 years ago
- fix: uglifier: https://github.com/lautis/uglifier/issues/127#issuecomment-352224986 — committed to cihad/teklifal by cihad 6 years ago
- Building off last commit, in production.rb, new change... ...to try to cure heroku deployment error. See here: https://github.com/lautis/uglifier/issues/127 — committed to breadoliveoilsalt/garden-tracker by breadoliveoilsalt 6 years ago
- Fix Uglifier issue See: https://github.com/lautis/uglifier/issues/127 — committed to picandocodigo/interstate_club by picandocodigo 6 years ago
- Update uglifier https://github.com/lautis/uglifier/issues/127 — committed to ChangJoo-Park/rails-stimulus-example by ChangJoo-Park 5 years ago
- Call Uglifier.new in production https://github.com/lautis/uglifier/issues/127#issuecomment-352224986 — committed to sharkipedia/sharkipedia by coffeejunk 5 years ago
- Fix(prod env): Enable ES6 syntax for asset precompilation Should solve the "Uglifier::Error: Unexpected token: name (input)" error https://github.com/lautis/uglifier/issues/127#issuecomment-352224986... — committed to hpi-swt2/vm-portal by chrisma 5 years ago
- cf issue https://github.com/lautis/uglifier/issues/127 to change assets js compressor — committed to CharlesDiGI/plus_de_chatounes by CharlesDiGI 5 years ago
- Merge pull request #72 from CharlesDiGI/delivery cf issue https://github.com/lautis/uglifier/issues/127 to change asse… — committed to CharlesDiGI/plus_de_chatounes by CharlesDiGI 5 years ago
Try replacing
with
in
config/environments/production.rbabraham, you save my day
Thank you, that worked! - Is there any reason why I wouldn’t want to enable ES6 syntax or why this feature isn’t on by default?
@fwolfst Just use a rake task. This only checks the asset pipeline files. You may also want to check your vendor file. I had this issue and found out that eslint was converting a vendor file into es6 syntax.
thanks! was using duck duck go to search and couldnt find anything. switched to google and it was on the first page…
@abraham You are a superhero.
Nevermind, this was just a case of missing something as simple as
require 'uglifier'inproduction.rbSilly me.
Thanks abraham !
In case anyone comes here looking for a solution to a similar error:
I recommend following this solution and switch to terser-ruby
Repalced config.assets.js_compressor = :uglifier with
config.assets.js_compressor = Uglifier.new(harmony: true) in config/environments/production.rb
as suggested by @abraham abraham but i am encountering new error after this
Uglifier::Error: Unexpected token punc «;», expected punc «,»
Could you please suggest howto fix.
config.assets.js_compressor = Uglifier.new(harmony: true) didn’t work for me, but I going up 3 release levels from 1.X something it got a lot better. Try going to ‘4.0.2’.
Is there any way to figure out which source JS-file is the culprit? iiuc, the error happens while compressing javascript code, so in theory there should be a solution by cleaning up the code before compression, isnt it?
I ran into this issue because Prettier was formatting an old jQuery file and adding ES6 syntax. Just throwing this solution in there in case someone gets stuck. Just save the file without Prettier.