尝试将 Rails 应用程序部署到 heroku 时出现 Uglifier 错误
Posted
技术标签:
【中文标题】尝试将 Rails 应用程序部署到 heroku 时出现 Uglifier 错误【英文标题】:Uglifier error when trying to deploy Rails5 app to heroku 【发布时间】:2019-04-07 01:43:54 【问题描述】:运行 RAILS_ENV=production bin/rails assets:precompileRAILS_ENV=production bin/rails assets:precompile
开始预编译过程,但它立即出错并显示以下消息(供参考,here 是 repo):
[1/5] Validating package.json...
[2/5] Resolving packages...
success Nothing to install.
success Saved lockfile.
Done in 0.18s.
rails aborted!
Uglifier::Error: Unexpected token: name (rails)
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/uglifier-4.1.20/lib/uglifier.rb:234:in `parse_result'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/uglifier-4.1.20/lib/uglifier.rb:216:in `run_uglifyjs'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/uglifier-4.1.20/lib/uglifier.rb:168:in `compile'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/compressing.rb:65:in `block in js_compressor='
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy_proc_processor.rb:31:in `call'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in `block in load'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in `load'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in `load'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in `find_asset'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:142:in `block in find'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `each'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `stat_directory'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:227:in `stat_tree'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `each'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `block in logical_paths'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `each'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `logical_paths'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:140:in `find'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in `compile'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in `with_logger'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/railties-5.2.3/lib/rails/command.rb:48:in `invoke'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<main>'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.4.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.4.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.4.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.4.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.4.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
/home/mkrul/Desktop/projects/cloned_factory_ops/factory-ops/bin/rails:9:in `<top (required)>'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
/home/mkrul/Desktop/projects/cloned_factory_ops/factory-ops/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
mkrul@mkrul-ThinkPad-T440s:~/Desktop/projects/cloned_factory_ops/factory-ops$
mkrul@mkrul-ThinkPad-T440s:~/Desktop/projects/cloned_factory_ops/factory-ops$ RAILS_ENV=production bin/rails assets:precompileRAILS_ENV=production bin/rails assets:precompile
rails aborted!
Don't know how to build task 'assets:precompileRAILS_ENV=production' (See the list of available tasks with `rake --tasks`)
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/railties-5.2.3/lib/rails/command.rb:48:in `invoke'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<main>'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.4.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.4.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.4.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.4.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.4.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
/home/mkrul/Desktop/projects/cloned_factory_ops/factory-ops/bin/rails:9:in `<top (required)>'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
/home/mkrul/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
/home/mkrul/Desktop/projects/cloned_factory_ops/factory-ops/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
(See full trace by running task with --trace)
【问题讨论】:
只用这个试试RAILS_ENV=production rails assets:precompile
根据您的日志Don't know how to build task 'assets:precompileRAILS_ENV=production' (See the list of available tasks with
rake --tasks)
这不是命令。请删除precompile
之后的内容或添加空格
【参考方案1】:
我认为问题是环境变量需要一个空间分隔试试这个
RAILS_ENV=production bin/rails assets:precompile
【讨论】:
以上是关于尝试将 Rails 应用程序部署到 heroku 时出现 Uglifier 错误的主要内容,如果未能解决你的问题,请参考以下文章
是啥阻止了这个 rails/vue 项目部署到 heroku?
在 Heroku 上部署 ActionCable (Rails 5 beta4)