gpt4 book ai didi

ruby-on-rails - 由于 Uglifier 错误 (Uglifier::Error),Rails 不会预编译 Assets

转载 作者:行者123 更新时间:2023-12-05 04:55:06 31 4
gpt4 key购买 nike

当运行 RAILS_ENV=production rake assets:precompile 时,我得到一个关于 Uglifier 的错误,如下所示:

root@4d24cd4a5e73:/myapp# RAILS_ENV=production rake assets:precompile
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
I, [2021-01-05T03:02:20.063081 #1157] INFO -- : Writing /myapp/public/assets/devise-47cffe5a2e3ba6e30007c165a43ffece5c9f22dffd9aa74fd1d16997604531d6.js
I, [2021-01-05T03:02:20.064339 #1157] INFO -- : Writing /myapp/public/assets/devise-47cffe5a2e3ba6e30007c165a43ffece5c9f22dffd9aa74fd1d16997604531d6.js.gz
I, [2021-01-05T03:02:20.891999 #1157] INFO -- : Writing /myapp/public/assets/devise-21d500da162dd967a369767d6e63a850741756ad45ad5ee5585b3000404b5aec.css
I, [2021-01-05T03:02:20.892583 #1157] INFO -- : Writing /myapp/public/assets/devise-21d500da162dd967a369767d6e63a850741756ad45ad5ee5585b3000404b5aec.css.gz
I, [2021-01-05T03:02:23.132038 #1157] INFO -- : Writing /myapp/public/assets/theme_metrica-d858c65c360f07333101ab2929374a9a0a32010684107f1342b8bd3fd904619f.css
I, [2021-01-05T03:02:23.132473 #1157] INFO -- : Writing /myapp/public/assets/theme_metrica-d858c65c360f07333101ab2929374a9a0a32010684107f1342b8bd3fd904619f.css.gz
I, [2021-01-05T03:02:24.038975 #1157] INFO -- : Writing /myapp/public/assets/default-d59db161d4cc7a0b511555c8e661e0d8b2b4b03baa22106b7e07cbf356664725.js
I, [2021-01-05T03:02:24.039591 #1157] INFO -- : Writing /myapp/public/assets/default-d59db161d4cc7a0b511555c8e661e0d8b2b4b03baa22106b7e07cbf356664725.js.gz
rake aborted!
Uglifier::Error:
/usr/local/bundle/gems/uglifier-4.2.0/lib/uglifier.rb:291:in `parse_result'
/usr/local/bundle/gems/uglifier-4.2.0/lib/uglifier.rb:221:in `run_uglifyjs'
/usr/local/bundle/gems/uglifier-4.2.0/lib/uglifier.rb:166:in `compile'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/compressing.rb:65:in `block in js_compressor='
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/legacy_proc_processor.rb:31:in `call'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in `block in load'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in `load'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in `load'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in `find_asset'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:142:in `block in find'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `each'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `stat_directory'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:227:in `stat_tree'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `each'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `block in logical_paths'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `each'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `logical_paths'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:140:in `find'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in `compile'
/usr/local/bundle/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:67:in `block (3 levels) in define'
/usr/local/bundle/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in `with_logger'
/usr/local/bundle/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:66:in `block (2 levels) in define'
/usr/local/bundle/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
root@4d24cd4a5e73:/myapp#

事实证明这是由于在我的应用程序中使用了 ckeditor5。如果我从我的 application.js 文件中删除以下行,那么它就可以预编译了:

//= require ckeditor5/build/ckeditor.js

我以前遇到过这种情况,只需修改我的 config/environment/production.rb 文件即可:

  # Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier

  # Compress JavaScripts and CSS.
config.assets.js_compressor = Uglifier.new(:harmony => true)

这已经工作了很长一段时间,但现在我遇到了同样的错误。 Ruby on Rails Error: Uglifier::Error: Unexpected token: operator (<) 提出的解决方案建议做完全相同的事情,但这不再适合我。

最佳答案

我在 2 个不同的 Rails 应用程序(相同的 parse_result 消息和 uglifier 版本)中遇到了这个问题,发现它不支持 ES6,所以一些最近更新的依赖项不再被 uglifier 压缩。我通过切换到 terser 解决了这个问题,这不是一个困难的转换:

https://github.com/publiclab/plots2/issues/11232 , 固定在 https://github.com/publiclab/plots2/pull/11243

关于ruby-on-rails - 由于 Uglifier 错误 (Uglifier::Error),Rails 不会预编译 Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65580629/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com