Skip to content
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: - Solution: Switch to terser #185

Open
rgaufman opened this issue May 24, 2022 · 17 comments
Open

Uglifier::Error: - Solution: Switch to terser #185

rgaufman opened this issue May 24, 2022 · 17 comments

Comments

@rgaufman
Copy link

rgaufman commented May 24, 2022

Hi there,

I am using:

  • Ruby 3.1.2p20
  • Rails 7.0.3
  • Uglifier 4.2.0

In a previous version of Rails/Ruby (Rails 6 on Ruby 3.0), it was working correctly. However now I just see this:

$ RAILS_ENV=production bundle exec rails assets:precompile
autoprefixer: /Users/hackeron/Development/Tether/timeline/app/assets/stylesheets/application_dark_theme.scss:26033:3: Replace color-adjust to print-color-adjust. The color-adjust shorthand is currently deprecated.
rails aborted!
Uglifier::Error:

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

When I run with trace, I see this:

$ RAILS_ENV=production bundle exec rails assets:precompile --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Execute assets:precompile
autoprefixer: /Users/hackeron/Development/Tether/timeline/app/assets/stylesheets/application_dark_theme.scss:26033:3: Replace color-adjust to print-color-adjust. The color-adjust shorthand is currently deprecated.
rails aborted!
Uglifier::Error:
/usr/local/lib/ruby/gems/3.1.0/gems/uglifier-4.2.0/lib/uglifier.rb:291:in `parse_result'
/usr/local/lib/ruby/gems/3.1.0/gems/uglifier-4.2.0/lib/uglifier.rb:221:in `run_uglifyjs'
/usr/local/lib/ruby/gems/3.1.0/gems/uglifier-4.2.0/lib/uglifier.rb:166:in `compile'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/compressing.rb:84:in `block in js_compressor='
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/processor_utils.rb:84:in `call_processor'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/processor_utils.rb:65:in `call_processors'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/loader.rb:182:in `load_from_unloaded'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/loader.rb:59:in `block in load'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/loader.rb:43:in `load'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/cached_environment.rb:44:in `load'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/bundle.rb:32:in `block in call'
/usr/local/Cellar/ruby/3.1.2/lib/ruby/3.1.0/set.rb:511:in `each_key'
/usr/local/Cellar/ruby/3.1.2/lib/ruby/3.1.0/set.rb:511:in `each'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/bundle.rb:31:in `call'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/processor_utils.rb:84:in `call_processor'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/processor_utils.rb:65:in `call_processors'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/loader.rb:182:in `load_from_unloaded'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/loader.rb:59:in `block in load'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/loader.rb:43:in `load'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/cached_environment.rb:44:in `load'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/base.rb:81:in `find_asset'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/base.rb:88:in `find_all_linked_assets'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/manifest.rb:125:in `each'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/manifest.rb:125:in `to_a'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/manifest.rb:125:in `block (2 levels) in find'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `block in synchronize'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:22:in `execute'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/promise.rb:564:in `block in realize'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:352:in `run_task'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:343:in `block (3 levels) in create_worker'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `loop'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `block (2 levels) in create_worker'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:333:in `catch'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:333:in `block in create_worker'
Tasks: TOP => assets:precompile

The autoprefixer warning shows up when I disable uglifier too and doesn't seem to be related to this.

I can't for the life of me figure out what's wrong... any ideas how to troubleshoot this or what could be going wrong?

@puneetpandey
Copy link

I am getting the same error during rake assets:precompile when deploying my Rails application to Elastic Beanstalk.

I am using:

  • Ruby: 2.7.5
  • Rails: 7.0.0
  • Uglifier: 4.2.0
  • sprockets-rails (3.4.2)
[INFO] Running command /bin/su webapp -c bundle exec /opt/elasticbeanstalk/config/private/checkforraketask.rb assets:precompile
[INFO] Found assets:precompile task in Rakefile
[INFO] Running command /bin/su webapp -c bundle exec rake assets:precompile
[INFO] /var/app/staging/app/models/user.rb:74: warning: key :unless is duplicated and overwritten on line 74
I, INFO -- : Writing /var/app/staging/public/assets/base-e93877bbc318b48cb1dc6dd89b3ed50cb854f5b0ed7cbb3c611ef086b54d0abd.js
I, [2022-05-24T14:49:20.044390 #1920]  INFO -- : Writing /var/app/staging/public/assets/base-e93877bbc318b48cb1dc6dd89b3ed50cb854f5b0ed7cbb3c611ef086b54d0abd.js.gz
rake aborted!
Uglifier::Error: 
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/uglifier-4.2.0/lib/uglifier.rb:291:in `parse_result'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/uglifier-4.2.0/lib/uglifier.rb:221:in `run_uglifyjs'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/uglifier-4.2.0/lib/uglifier.rb:166:in `compile'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/compressing.rb:65:in `block in js_compressor='
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/legacy_proc_processor.rb:31:in `call'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in `block in load'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in `load'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in `load'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in `find_asset'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:134:in `block in find'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:133:in `each'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:133:in `find'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in `compile'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/task.rb:67:in `block (3 levels) in define'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in `with_logger'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/task.rb:66:in `block (2 levels) in define'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/opt/elasticbeanstalk/.rbenv/versions/2.7.5/bin/bundle:25:in `load'
/opt/elasticbeanstalk/.rbenv/versions/2.7.5/bin/bundle:25:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

@puneetpandey
Copy link

As per #173 I am trying to downgrade Uglifier to 4.1.0 to see if it works

@rgaufman
Copy link
Author

rgaufman commented May 26, 2022

When I downgrade to 4.1.0, I see this:

RAILS_ENV=production bundle exec rails assets:precompile
rails aborted!
Uglifier::Error: Unexpected token: punc (.)

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

When I add --trace, I also see:

/usr/local/lib/ruby/gems/3.1.0/gems/uglifier-4.1.0/lib/uglifier.rb:236:in `parse_result'
/usr/local/lib/ruby/gems/3.1.0/gems/uglifier-4.1.0/lib/uglifier.rb:218:in `run_uglifyjs'
/usr/local/lib/ruby/gems/3.1.0/gems/uglifier-4.1.0/lib/uglifier.rb:168:in `compile'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/compressing.rb:84:in `block in js_compressor='
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/processor_utils.rb:84:in `call_processor'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/processor_utils.rb:65:in `call_processors'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/loader.rb:182:in `load_from_unloaded'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/loader.rb:59:in `block in load'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/loader.rb:43:in `load'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/cached_environment.rb:44:in `load'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/base.rb:81:in `find_asset'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/base.rb:88:in `find_all_linked_assets'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/manifest.rb:125:in `each'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/manifest.rb:125:in `to_a'
/usr/local/lib/ruby/gems/3.1.0/gems/sprockets-4.0.3/lib/sprockets/manifest.rb:125:in `block (2 levels) in find'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `block in synchronize'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:22:in `execute'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/promise.rb:564:in `block in realize'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:352:in `run_task'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:343:in `block (3 levels) in create_worker'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `loop'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `block (2 levels) in create_worker'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:333:in `catch'
/usr/local/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:333:in `block in create_worker'
Tasks: TOP => assets:precompile

@puneetpandey
Copy link

Not worked for me either. I got this:

[INFO] Running command /bin/su webapp -c bundle exec /opt/elasticbeanstalk/config/private/checkforraketask.rb assets:precompile
[INFO] Found assets:precompile task in Rakefile
[INFO] Running command /bin/su webapp -c bundle exec rake assets:precompile
[INFO] /var/app/staging/app/models/user.rb:74: warning: key :unless is duplicated and overwritten on line 74
I, INFO -- : Writing /var/app/staging/public/assets/base-e93877bbc318b48cb1dc6dd89b3ed50cb854f5b0ed7cbb3c611ef086b54d0abd.js
I, INFO -- : Writing /var/app/staging/public/assets/base-e93877bbc318b48cb1dc6dd89b3ed50cb854f5b0ed7cbb3c611ef086b54d0abd.js.gz
rake aborted!
NoMethodError: undefined method `start_with?' for nil:NilClass
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/uglifier-4.1.20/lib/uglifier.rb:225:in `error_message'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/uglifier-4.1.20/lib/uglifier.rb:234:in `parse_result'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/uglifier-4.1.20/lib/uglifier.rb:216:in `run_uglifyjs'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/uglifier-4.1.20/lib/uglifier.rb:168:in `compile'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/compressing.rb:65:in `block in js_compressor='
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/legacy_proc_processor.rb:31:in `call'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in `block in load'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in `load'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in `load'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in `find_asset'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:134:in `block in find'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:133:in `each'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:133:in `find'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in `compile'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/task.rb:67:in `block (3 levels) in define'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in `with_logger'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/task.rb:66:in `block (2 levels) in define'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/opt/elasticbeanstalk/.rbenv/versions/2.7.5/bin/bundle:25:in `load'
/opt/elasticbeanstalk/.rbenv/versions/2.7.5/bin/bundle:25:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

I am using this syntax:

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

No clue what to do next!

@puneetpandey
Copy link

@rgaufman are you using @import syntax in your stylesheets? I read this answer https://stackoverflow.com/a/70470984/649868 on StackOverflow to convert .scss to .css and use require instead of @import. Not sure how useful it is and if it fits into our case! Just a FYI

@puneetpandey
Copy link

Hi @rgaufman, replacing config.assets.js_compressor = Uglifier.new(harmony: true) with the block below:

config.assets.configure do |env|
  env.js_compressor  = :uglifier # or :closure, :yui
  env.css_compressor = :sass   # or :yui
end

worked for me. I have gem "sprockets-rails", :require => 'sprockets/railtie' in my Gemfile.

Need to confirm if this is a valid fix.

@rgaufman
Copy link
Author

I need the harmony: true option as I have a lot of ES6 syntax :(

@rgaufman
Copy link
Author

Oh wait, this did actually work, thank you! -- What a great workaround :D

@puneetpandey
Copy link

puneetpandey commented May 26, 2022

yeah this worked but did it compressed Javascripts with ES6 syntaxes properly? I am now validating this at my end as well

@puneetpandey
Copy link

As per Uglifier's Readme: UglifyJS only works with ES5. If you need to compress ES6, ruby-terser is a better option. It seems ES6 won't work well with Uglifier

@rgaufman
Copy link
Author

It seems to work, but I have coffee script and I think the asset pipeline is doing some heavy lifting? - terser looks interesting! - Have you switched to this from uglier? - it's strange I don't see it in the ruby docs, Uglifier appears to be the only option that doesn't have Java as a dependency from what I can tell!

@puneetpandey
Copy link

I am in process of testing terser. It seems both Uglifier and Terser works on execJS so switching is very easy

@rgaufman
Copy link
Author

I tried terser and it seems to have worked as a drop in replacement, I haven't seen any issues with the output yet. Thank you for the workarounds, that's super helpful!

@puneetpandey
Copy link

Worked for me too without any issues

@rgaufman rgaufman changed the title Uglifier::Error: Uglifier::Error: - Solution: Switch to terser May 29, 2022
@RoRroland
Copy link

Thanks @puneetpandey fix my issue too.

nicolas-entourage added a commit to ReseauEntourage/entourage-ror that referenced this issue Apr 24, 2023
Uglifier(harmony: true) fails; :uglifier does not suit for ES6

See: lautis/uglifier#185
nicolas-entourage added a commit to ReseauEntourage/entourage-ror that referenced this issue Jul 3, 2023
Uglifier(harmony: true) fails; :uglifier does not suit for ES6

See: lautis/uglifier#185
nicolas-entourage added a commit to ReseauEntourage/entourage-ror that referenced this issue Jul 7, 2023
Uglifier(harmony: true) fails; :uglifier does not suit for ES6

See: lautis/uglifier#185
nicolas-entourage added a commit to ReseauEntourage/entourage-ror that referenced this issue Jul 31, 2023
Uglifier(harmony: true) fails; :uglifier does not suit for ES6

See: lautis/uglifier#185
nicolas-entourage added a commit to ReseauEntourage/entourage-ror that referenced this issue Aug 2, 2023
Uglifier(harmony: true) fails; :uglifier does not suit for ES6

See: lautis/uglifier#185
manno added a commit to voc/voctoweb that referenced this issue Dec 25, 2023
Failed to deploy on production with:

Uglifier::Error:
../gems/uglifier-4.2.0/lib/uglifier.rb:291:in `parse_result'

See lautis/uglifier/issues/185
jxjj added a commit to UMN-LATIS/z that referenced this issue Apr 23, 2024
Deploying fails on the `assets:precompile` step with:
```
Uglifier::Error:  (Uglifier::Error)
/uglifier.rb:291:in `parse_result'
```

Issue here: lautis/uglifier#185

There's a workaround suggested in the issue, but it's also suggested to move to the [Terser gem](https://github.com/ahorek/terser-ruby) as Uglifier's last update was more than 5 years ago, and Terser's is 3 weeks ago.

This moves to the Terser gem.
tpendragon added a commit to pulibrary/dpul that referenced this issue Aug 16, 2024
tpendragon added a commit to pulibrary/dpul that referenced this issue Sep 11, 2024
@msxavi
Copy link

msxavi commented Nov 8, 2024

Same problem here in Rails 7.1.

[20] pry(#<Uglifier>)> Uglifier::VERSION
=> "4.2.1"
[21] pry(#<Uglifier>)> ExecJS::VERSION
=> "2.10.0"
[22] pry(#<Uglifier>)> context.call("uglifier", options)
=> {"error"=>{}}

My config uses harmony too:

config.assets.js_compressor = Uglifier.new(harmony: true, compress: { unused: false })

Interesting that @puneetpandey solution works with configure. However config.assets.js_compressor = :uglifier does not.

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

Alternatively:

  config.assets.configure do |env|
    env.js_compressor = Uglifier.new(harmony: true, compress: { unused: false })
  end

@rgaufman
Copy link
Author

rgaufman commented Nov 8, 2024

Use terser instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants