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 in production mode on RoR 7.0.3.1 with Bootstrap 5.2 #187

Open
Sega100500 opened this issue Aug 4, 2022 · 16 comments
Open

Comments

@Sega100500
Copy link

Sega100500 commented Aug 4, 2022

Ruby 3.1.2
Ruby on Rails 7.0.3.1
gem Uglifier 4.2.0
Third party library: Bootstrap 5.2 ( new version 5.2 released )

With bootstrap 5.1.3 (previous version) all works fine!

app/assets/config/manifest.js :

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css

//= link lib/bootstrap/5.2.0/js/bootstrap.bundle.min.js
//= link lib/bootstrap/5.2.0/js/bootstrap.min.js
//= link lib/bootstrap/5.2.0/css/bootstrap.min.css

in view stylesheets and javascripts are attached via stylesheet_link_tag and javascript_include_tag

config/environments/production.rb :

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

log/production.log :

I, [2022-08-04T20:29:16.542499 #11922]  INFO -- : [425e1b3d-5d27-4e00-afdf-d698f79e50ab] Started GET "/" for 127.0.0.1 at 2022-08-04 20:29:16 +0500
I, [2022-08-04T20:29:16.545698 #11922]  INFO -- : [425e1b3d-5d27-4e00-afdf-d698f79e50ab] Processing by ApplicationBaseController#index as HTML
I, [2022-08-04T20:29:16.554844 #11922]  INFO -- : [425e1b3d-5d27-4e00-afdf-d698f79e50ab]   Rendered application_base/index.html.erb within layouts/application (Duration: 0.9ms | Allocations: 314)
I, [2022-08-04T20:29:33.586606 #11922]  INFO -- : [425e1b3d-5d27-4e00-afdf-d698f79e50ab]   Rendered layout layouts/application.html.erb (Duration: 17032.8ms | Allocations: 628213)
I, [2022-08-04T20:29:33.586988 #11922]  INFO -- : [425e1b3d-5d27-4e00-afdf-d698f79e50ab] Completed 500 Internal Server Error in 17041ms (ActiveRecord: 0.7ms | Allocations: 630135)
F, [2022-08-04T20:29:33.587842 #11922] FATAL -- : [425e1b3d-5d27-4e00-afdf-d698f79e50ab]   
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] ActionView::Template::Error (
):
[425e1b3d-5d27-4e00-afdf-d698f79e50ab]   
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] uglifier (4.2.0) lib/uglifier.rb:291:in `parse_result'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] uglifier (4.2.0) lib/uglifier.rb:221:in `run_uglifyjs'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] uglifier (4.2.0) lib/uglifier.rb:166:in `compile'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/compressing.rb:84:in `block in js_compressor='
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/processor_utils.rb:84:in `call_processor'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/processor_utils.rb:66:in `block in call_processors'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/processor_utils.rb:65:in `reverse_each'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/processor_utils.rb:65:in `call_processors'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/loader.rb:182:in `load_from_unloaded'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/loader.rb:59:in `block in load'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/loader.rb:43:in `load'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/cached_environment.rb:44:in `block in load'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/cached_environment.rb:44:in `fetch'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/cached_environment.rb:44:in `load'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/bundle.rb:32:in `block in call'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] /home/ruby/.rbenv/versions/3.1.2/lib/ruby/3.1.0/set.rb:511:in `each_key'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] /home/ruby/.rbenv/versions/3.1.2/lib/ruby/3.1.0/set.rb:511:in `each'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/bundle.rb:31:in `call'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/processor_utils.rb:84:in `call_processor'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/processor_utils.rb:66:in `block in call_processors'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/processor_utils.rb:65:in `reverse_each'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/processor_utils.rb:65:in `call_processors'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/loader.rb:182:in `load_from_unloaded'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/loader.rb:59:in `block in load'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/loader.rb:43:in `load'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/cached_environment.rb:44:in `block in load'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/cached_environment.rb:44:in `fetch'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/cached_environment.rb:44:in `load'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/bundle.rb:32:in `block in call'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] /home/ruby/.rbenv/versions/3.1.2/lib/ruby/3.1.0/set.rb:511:in `each_key'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] /home/ruby/.rbenv/versions/3.1.2/lib/ruby/3.1.0/set.rb:511:in `each'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/bundle.rb:31:in `call'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/processor_utils.rb:84:in `call_processor'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/processor_utils.rb:66:in `block in call_processors'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/processor_utils.rb:65:in `reverse_each'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/processor_utils.rb:65:in `call_processors'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/loader.rb:182:in `load_from_unloaded'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/loader.rb:59:in `block in load'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/loader.rb:43:in `load'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/cached_environment.rb:44:in `block in load'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/cached_environment.rb:44:in `fetch'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/cached_environment.rb:44:in `load'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/base.rb:81:in `find_asset'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/base.rb:88:in `find_all_linked_assets'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/manifest.rb:125:in `each'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/manifest.rb:125:in `to_a'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] sprockets (4.1.1) lib/sprockets/manifest.rb:125:in `block (2 levels) in find'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] concurrent-ruby (1.1.10) lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] concurrent-ruby (1.1.10) lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `block in synchronize'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] concurrent-ruby (1.1.10) lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] concurrent-ruby (1.1.10) lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] concurrent-ruby (1.1.10) lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:22:in `execute'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] concurrent-ruby (1.1.10) lib/concurrent-ruby/concurrent/promise.rb:564:in `block in realize'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] concurrent-ruby (1.1.10) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:352:in `run_task'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] concurrent-ruby (1.1.10) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:343:in `block (3 levels) in create_worker'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] concurrent-ruby (1.1.10) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `loop'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] concurrent-ruby (1.1.10) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `block (2 levels) in create_worker'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] concurrent-ruby (1.1.10) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:333:in `catch'
[425e1b3d-5d27-4e00-afdf-d698f79e50ab] concurrent-ruby (1.1.10) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:333:in `block in create_worker'

All other compressors are works with errors in this case

@Sega100500
Copy link
Author

Some refer to the need to use a terser , but terser does'nt work properly at this case too.

@dave105010
Copy link

dave105010 commented Aug 11, 2022

Sorry I found this issue while looking into something else about terser/rails on Google. What's the problem here exactly? rails assets:precompile generates the minified JS when the command is explicitly executed on terminal? Why uglifier is running on application runtime anyway? So weird. Maybe it shouldn't run at all. Uglifier devs should fix that.

Does the minified js file work when you remove uglifier gem and rebooted the application?

@Sega100500
Copy link
Author

Sega100500 commented Aug 11, 2022

@dave105010
Because I don't use rails assets:precompile any time but I use config.assets.compile = true in config file (see the issue).

In development mode, everything works fine until :uglifier is used. The JS code and CSS styles has nothing to do with it at all.

@Jaco-Pretorius
Copy link

Jaco-Pretorius commented Aug 12, 2022

+1 Also seeing this exact same issue when upgrading Bootstrap in both Development and Production

I'm seeing this when I run assets:precompile:

rails aborted!
Uglifier::Error:
/Users/my-username/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/uglifier-4.2.0/lib/uglifier.rb:293:in `parse_result'
/Users/my-username/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/uglifier-4.2.0/lib/uglifier.rb:221:in `run_uglifyjs'
/Users/my-username/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/uglifier-4.2.0/lib/uglifier.rb:166:in `compile'

The result parameter in parse_result (which I found by adding some debug statements) is {"error"=>{}}

@itsalongstory
Copy link

# gem 'uglifier', '~> 4.2'
gem 'terser', '~> 1.1', '>= 1.1.12'
# config.assets.js_compressor = Uglifier.new(harmony: true)
config.assets.js_compressor = :terser

@Sega100500
Copy link
Author

@itsalongstory
terser have same problem. It' not solution!

@itsalongstory
Copy link

terser have same problem. It' not solution!

So, how did you get Uglifier to handle Bootstrap 5.2 correctly now?

@Sega100500
Copy link
Author

@itsalongstory
No way! I don't see a solution, so I stayed on Bootstrap v5.1.3 for now. The fact is that technology is advancing, and RoR is no longer keeping up with them.

@itsalongstory
Copy link

terser have same problem. It' not solution!

Can you describe a little bit about the problems you've encountered with terser?

@Sega100500
Copy link
Author

@itsalongstory
Same problem as uglifier - not work correctly when I use Bootstrap 5.2

@itsalongstory
Copy link

Same problem as uglifier - not work correctly when I use Bootstrap 5.2

In my project, uglifier does not work with Bootstrap 5.2, but terser works fine with Bootstrap 5.2

@Jaco-Pretorius
Copy link

No way! I don't see a solution, so I stayed on Bootstrap v5.1.3 for now. The fact is that technology is advancing, and RoR is no longer keeping up with them.

I think we should first understand why it's blowing up. It's not clear to me if the issue is in uglifier or in Bootstrap.

@itsalongstory
Copy link

itsalongstory commented Aug 16, 2022

No way! I don't see a solution, so I stayed on Bootstrap v5.1.3 for now. The fact is that technology is advancing, and RoR is no longer keeping up with them.

I think we should first understand why it's blowing up. It's not clear to me if the issue is in uglifier or in Bootstrap.

I think the problem is uglifier doesn't full support ES6, and Bootstrap 5.2 has some new ES6 code.

@Jaco-Pretorius
Copy link

@itsalongstory Ah, ok - that explains it.

The README does say UglifyJS only works with ES5. If you need to compress ES6, [ruby-terser](https://github.com/ahorek/terser-ruby) is a better option.

I switched to terser and that solved my problem, so I think that's the resolution for this issue. If terser doesn't work for you I would suggest opening an issue against the terser repo.

@bekkou68
Copy link

I faced a similar problem. And I solved the problem by switching to terser. Thanks.

@guilhermeyo
Copy link

@bekkou68 me too, thanks.

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

6 participants