New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uglifier::Error: Unexpected token: punc ((). To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true) #127

Closed
goldenstar999 opened this Issue Dec 12, 2017 · 23 comments

Comments

Projects
None yet
@goldenstar999
Copy link

goldenstar999 commented Dec 12, 2017

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

'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

How to fix this issue?

@goldenstar999

This comment has been minimized.

Copy link

goldenstar999 commented Dec 12, 2017

I ran this commands on command line.

rails c
Uglifier.compile(File.read('app/assets/javascripts/states/CityState.js'))

I got this error:

Uglifier::Error: Unexpected token: punc ((). To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true).
from /Users/leonverspeek/.rvm/gems/ruby-2.3.1@zombie/gems/uglifier-4.0.2/lib/uglifier.rb:237:in `parse_result'

How to fix this?

@abraham

This comment has been minimized.

Copy link

abraham commented Dec 17, 2017

Try replacing

config.assets.js_compressor = :uglifier

with

config.assets.js_compressor = Uglifier.new(harmony: true)

in config/environments/production.rb

@lautis lautis closed this in d20a5b8 Dec 28, 2017

@chengs2416me

This comment has been minimized.

Copy link

chengs2416me commented Jan 4, 2018

abraham, you save my day

@Peskoo

This comment has been minimized.

Copy link

Peskoo commented Jan 5, 2018

Thanks abraham !

@rgaufman

This comment has been minimized.

Copy link

rgaufman commented Jan 19, 2018

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?

@lautis

This comment has been minimized.

Copy link
Owner

lautis commented Jan 22, 2018

ES6 is not enabled in the master branch of UglifyJS. I've considered more or less beta, so it's not enabled by default.

Sinetheta added a commit to Sinetheta/payment_request_api that referenced this issue Mar 7, 2018

moveson added a commit to SplitTime/OpenSplitTime that referenced this issue Mar 7, 2018

sizer added a commit to sizer/locateit that referenced this issue Apr 1, 2018

mccollek added a commit to mccollek/data-dictionary that referenced this issue May 17, 2018

lucfranken added a commit to lucfranken/diy10 that referenced this issue May 19, 2018

uglifier stuff
Uglifier.new(harmony: true)

lautis/uglifier#127 (comment)
@geminiyellow

This comment has been minimized.

Copy link

geminiyellow commented Jun 22, 2018

woo! amazing!

@AdnanTheExcellent

This comment has been minimized.

Copy link

AdnanTheExcellent commented Jul 9, 2018

I encountered this issue when upgrading to rails 5.2 (and a few other gems). However, I'm now getting this error when i update the js_compressor line (to config.assets.js_compressor = Uglifier.new(harmony: true)) that @abraham suggested:

error:
Sprockets::Error: unknown compressor: js_compressor

stack trace:

rake aborted!
Sprockets::Error: unknown compressor: js_compressor
/home/nestmg6/.rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/compressing.rb:63:in `js_compressor='
/home/nestmg6/.rvm/gems/ruby-2.5.1/bundler/gems/requirejs-rails-1479da3c1c26/lib/tasks/requirejs-rails_tasks.rake:123:in `block (3 levels) in <top (required)>'
/home/nestmg6/.rvm/gems/ruby-2.5.1/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
Tasks: TOP => requirejs:precompile:all => requirejs:precompile:digestify_and_compress => requirejs:precompile:run_rjs => requirejs:precompile:prepare_source
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/usr/local/rvm/rubies/ruby-2.5.1/bin/ruby ...]
/home/nestmg6/.rvm/gems/ruby-2.5.1/bundler/gems/requirejs-rails-1479da3c1c26/lib/tasks/requirejs-rails_tasks.rake:18:in `ruby_rake_task'
/home/nestmg6/.rvm/gems/ruby-2.5.1/bundler/gems/requirejs-rails-1479da3c1c26/lib/tasks/requirejs-rails_tasks.rake:83:in `block (3 levels) in <top (required)>'
/home/nestmg6/.rvm/gems/ruby-2.5.1/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
/home/nestmg6/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `eval'
/home/nestmg6/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => assets:precompile => requirejs:precompile:external

Any idea why i'm getting this? I am using uglifier 4.1.14

@abraham

This comment has been minimized.

Copy link

abraham commented Jul 10, 2018

@AdnanTheExcellent Looks like you are running into this jwhitley/requirejs-rails#206

@AdnanTheExcellent

This comment has been minimized.

Copy link

AdnanTheExcellent commented Jul 10, 2018

thanks! was using duck duck go to search and couldnt find anything. switched to google and it was on the first page...

mirelon pushed a commit to mirelon/prosody_analysis that referenced this issue Jul 17, 2018

Koh0214 added a commit to Koh0214/narou-susume that referenced this issue Jul 25, 2018

cihad added a commit to cihad/teklifal that referenced this issue Jul 28, 2018

notoriousgorilla added a commit to notoriousgorilla/HydroApp that referenced this issue Aug 8, 2018

jquery test 2
test 2 success. added "Uglifier.new(harmony: true)" to config/environment/production.rb 
See lautis/uglifier#127

alexanmtz added a commit to worknenjoy/truppie that referenced this issue Aug 19, 2018

@crwhitesides

This comment has been minimized.

Copy link

crwhitesides commented Sep 13, 2018

Thank you!

alexanmtz added a commit to worknenjoy/truppie that referenced this issue Sep 17, 2018

cihad added a commit to cihad/teklifal that referenced this issue Sep 20, 2018

@aivaco

This comment has been minimized.

Copy link

aivaco commented Oct 4, 2018

Thanks!

@deepkum

This comment has been minimized.

Copy link

deepkum commented Oct 9, 2018

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.

@protigen34

This comment has been minimized.

Copy link

protigen34 commented Oct 12, 2018

Hey, I updated uglifier to the latest version and I am seeing getting this error in the rake assets:precompile step while trying to push to heroku:

remote:        Uglifier::Error: Unexpected token: string (ProductChannel)

How can I fix the issue?

@Autumn-Martin Autumn-Martin referenced this issue Nov 2, 2018

Merged

53 prepare page links master am #82

9 of 9 tasks complete
@bnathan04

This comment has been minimized.

Copy link

bnathan04 commented Nov 10, 2018

After ensuring uglifier is the latest version, and following Abraham's step above, I still end up with the following error during the rake assets:precompile step while trying to push to heroku:

remote: Uglifier::Error: Unexpected token: operator (=)

Any suggestions on how to get by this problem?

breadoliveoilsalt added a commit to breadoliveoilsalt/garden-tracker that referenced this issue Nov 15, 2018

Building off last commit, in production.rb, new change...
...to try to cure heroku deployment error.  See here:

lautis/uglifier#127
@Rozaki0318

This comment has been minimized.

Copy link

Rozaki0318 commented Nov 20, 2018

Thank you so much, abraham!

@NelcifranMagalhaes

This comment has been minimized.

Copy link

NelcifranMagalhaes commented Nov 20, 2018

Nice...its save me @abraham XD

@felipepaifer

This comment has been minimized.

Copy link

felipepaifer commented Dec 4, 2018

Thank you!!!

@tommulliez

This comment has been minimized.

Copy link

tommulliez commented Dec 11, 2018

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 «,»

I'v got the same issus : Uglifier::Error: Unexpected token: punc (:)
Do you fixed it finally ? Thank you :-)

@drcenterprises

This comment has been minimized.

Copy link

drcenterprises commented Dec 15, 2018

@abraham thanks i worked for me

picandocodigo added a commit to picandocodigo/interstate_club that referenced this issue Dec 15, 2018

@arefin-zeno

This comment has been minimized.

Copy link

arefin-zeno commented Dec 28, 2018

Try replacing

config.assets.js_compressor = :uglifier

with

config.assets.js_compressor = Uglifier.new(harmony: true)

in config/environments/production.rb

@abraham You are a superhero.

@dsignr

This comment has been minimized.

Copy link

dsignr commented Jan 9, 2019

Try replacing

config.assets.js_compressor = :uglifier

with

config.assets.js_compressor = Uglifier.new(harmony: true)

in config/environments/production.rb

For some reason, this leads to:

rake aborted!
NameError: uninitialized constant Uglifier
@dsignr

This comment has been minimized.

Copy link

dsignr commented Jan 9, 2019

Try replacing

config.assets.js_compressor = :uglifier

with

config.assets.js_compressor = Uglifier.new(harmony: true)

in config/environments/production.rb

For some reason, this leads to:

rake aborted!
NameError: uninitialized constant Uglifier

Nevermind, this was just a case of missing something as simple as

require 'uglifier' in production.rb

Silly me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment