由于 "precompiling assets failed",Heroku 部署 rails5 应用程序失败

Heroku deploy failing for rails5 app due to "precompiling assets failed"

运行 git push heroku master 开始部署过程,但它似乎在以下阶段挂起:

remote:        Fetching sass-rails 5.0.7
remote:        Installing sass-rails 5.0.7

最后提示预编译资源失败

我觉得我已经尽了一切努力让它发挥作用。我正在努力尝试让应用程序部署的第 3 周。作为参考,这里是回购协议:https://github.com/mkrul/factory-ops

remote:        Post-install message from sass:
remote:        
remote:        Ruby Sass is deprecated and will be unmaintained as of 26 March 2019.
remote:        
remote:        * If you use Sass as a command-line tool, we recommend using Dart Sass, the new
remote:          primary implementation: https://sass-lang.com/install
remote:        
remote:        * If you use Sass as a plug-in for a Ruby web framework, we recommend using the
remote:          sassc gem: https://github.com/sass/sassc-ruby#readme
remote:        
remote:        * For more details, please refer to the Sass blog:
remote:          http://sass.logdown.com/posts/7081811
remote:        
remote:        Removing bundler (1.15.2)
remote:        Bundle completed (162.24s)
remote:        Cleaning up the bundler cache.
remote:        The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
remote: -----> Installing node-v10.14.1-linux-x64
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        Yarn executable was not detected in the system.
remote:        Download Yarn at https://yarnpkg.com/en/docs/install
remote:        rake aborted!
remote:        Uglifier::Error: Unexpected token: name (rails)
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/uglifier-4.1.20/lib/uglifier.rb:234:in `parse_result'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/uglifier-4.1.20/lib/uglifier.rb:216:in `run_uglifyjs'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/uglifier-4.1.20/lib/uglifier.rb:168:in `compile'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/compressing.rb:65:in `block in js_compressor='
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy_proc_processor.rb:31:in `call'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in `block in load'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in `load'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in `load'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in `find_asset'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:142:in `block in find'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `each'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `stat_directory'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:227:in `stat_tree'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `each'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `block in logical_paths'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `each'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `logical_paths'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:140:in `find'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in `compile'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in `with_logger'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
remote:        /tmp/build_515c8a50b0ac85c4870b659697d0fa8b/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
remote:        Tasks: TOP => assets:precompile
remote:        (See full trace by running task with --trace)
remote: 
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to bar-and-pub-supply.
remote: 
To https://git.heroku.com/bar-and-pub-supply.git
 ! [remote rejected] master -> master (pre-receive hook declined)

更新 4/6/8:40PM EST

更改 sass-file gem 和 production.rb 配置文件后,我 运行 RAILS_ENV=production bin/rails assets:precompile 收到以下错误:

[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)

这可能有几个不同的原因。

首先,正如 Heroku 警告您...使用 sassc 而不是 sass-rails...所以将您的 gemfile 中的 gem sass-rails 替换为 gem 'sassc-rails'

其次,尝试将以下内容添加到您的 config/environments/production.rb 文件(这将替换 config.assets.js_compressor = :uglifier..

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

如何让 Heroku 达到 return Don't know how to build task 'assets:precompileRAILS_ENV=production' (See the list of available tasks with rake --tasks)

通常此命令:bundle exec rake assets:precompile RAILS_ENV=production 将在您的控制台中本地完成。它允许您在本地编译您的资产。

另外,通过在本地执行此操作,您可能会获得有关无法预编译的文件的一些信息。然后尝试调试这个文件。它是 javascript 或 CSS 文件。

一些可能的错误:

  • Js 文件包括 ES6 => 然后你必须按照建议使用 Harmony 马克
  • 一些动态内容(如果您有 css.erb 或 js.erb 文件)

  • JS 文件中的一些拼写错误(CSS 拼写错误一直触发警告)

  • ..