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 Cannot Precompile JS Optional Chaining #174

Open
kduraiswami opened this issue Jun 1, 2020 · 3 comments
Open

Uglifier Cannot Precompile JS Optional Chaining #174

kduraiswami opened this issue Jun 1, 2020 · 3 comments

Comments

@kduraiswami
Copy link

Hi There

I am trying to precompile assets with config.assets.js_compressor = Uglifier.new(harmony: true) and I receive the error Uglifier::Error: Unexpected token: punc (.) for JS syntax like this: .data('id'))?.advanced_settings

Full Stacktrace:

/mypath/app/assets/config/manifest.js:2
/usr/local/rvm/gems/ruby-2.5.1/gems/uglifier-4.2.0/lib/uglifier.rb:291:in parse_result' /usr/local/rvm/gems/ruby-2.5.1/gems/uglifier-4.2.0/lib/uglifier.rb:221:in run_uglifyjs'
/usr/local/rvm/gems/ruby-2.5.1/gems/uglifier-4.2.0/lib/uglifier.rb:166:in compile' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/compressing.rb:65:in block in js_compressor='
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/legacy_proc_processor.rb:31:in call' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in call_processor'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in block in call_processors' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in reverse_each'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in call_processors' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in load_from_unloaded'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in block in load' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in fetch_asset_from_dependency_cache'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in load' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in block in initialize'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in load' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/directive_processor.rb:388:in load'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/directive_processor.rb:357:in block in link_paths' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/directive_processor.rb:367:in block in resolve_paths'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/directive_processor.rb:363:in each' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/directive_processor.rb:363:in resolve_paths'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/directive_processor.rb:356:in link_paths' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/directive_processor.rb:317:in process_link_directory_directive'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/directive_processor.rb:180:in block in process_directives' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/directive_processor.rb:178:in each'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/directive_processor.rb:178:in process_directives' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/directive_processor.rb:83:in _call'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/directive_processor.rb:68:in call' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in call_processor'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in block in call_processors' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in reverse_each'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in call_processors' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in load_from_unloaded'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in block in load' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in fetch_asset_from_dependency_cache'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in load' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in block in initialize'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in load' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/bundle.rb:23:in block in call'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/utils.rb:200:in dfs' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/bundle.rb:24:in call'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in call_processor' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in block in call_processors'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in reverse_each' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in call_processors'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in load_from_unloaded' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in block in load'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in fetch_asset_from_dependency_cache' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in load'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in block in initialize' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in load'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in find_asset' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in find_all_linked_assets'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:134:in block in find' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:133:in each'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:133:in find' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in compile'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in block (3 levels) in define' /usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in with_logger'
/usr/local/rvm/gems/ruby-2.5.1/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in block (2 levels) in define' /usr/local/rvm/gems/ruby-2.5.1/gems/rake-13.0.1/exe/rake:27:in <top (required)>'
/usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in eval' /usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in

'
Tasks: TOP => assets:precompile
Let me know if I can provide any additional context or if this has already been fixed elsewhere.

@sylwesternourish
Copy link

I am having the same issue when using Uglifier on Rails 5.2.3, is there any work around apart from disabling Uglifier?

@cs0511
Copy link

cs0511 commented Nov 26, 2020

Same issue

@mike-usa
Copy link

mike-usa commented Feb 28, 2022

The Safe Navigation / Optional Chaining operator (?.) was first introduced in ECMAScript 2020 (ES2020). For various reasons, Uglifier supports up to ES5 (ES6 with harmony: true). #43610 leads to (rails/sprockets#713), which mentions to use terser gem instead.

Add terser to the Gemfile

bundle install terser

Add it to your configuration files where you want to compress (e.g., config/production.rb):

config.assets.js_compressor = :terser

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