(导轨5)加载错误:部署到Heroku时无法加载此类文件-- sass...

ef1yzkbh  于 2022-11-13  发布在  其他
关注(0)|答案(3)|浏览(139)

我在部署Rails 5应用程序时,标题中出现了错误。我最近更新了Gemfile以包含一些更新的版本。我的本地开发环境没有任何问题,但当我推到Heroku时,它处于“生产模式”,出现了一个错误,似乎与资产预编译有关。
以下是我在日志中看到的内容:

remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        yarn install v1.22.10
remote:        [1/5] Validating package.json...
remote:        [2/5] Resolving packages...
remote:        success Nothing to install.
remote:        success Saved lockfile.
remote:        Done in 0.07s.
remote:        rake aborted!
remote:        LoadError: cannot load such file -- sass
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `require'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `block in require'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:257:in `load_dependency'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `require'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/autoload/sass.rb:1:in `<top (required)>'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `require'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `block in require'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:257:in `load_dependency'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `require'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/sass_processor.rb:47:in `initialize'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/sass_processor.rb:26:in `new'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/sass_processor.rb:26:in `instance'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/sass_processor.rb:34:in `cache_key'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:93:in `processor_cache_key'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:22:in `block in initialize'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:53:in `processor_cache_key'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:102:in `block in processors_cache_keys'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:102:in `map'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:102:in `processors_cache_keys'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processing.rb:159:in `resolve_processors_cache_key_uri'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets.rb:162:in `block in <module:Sprockets>'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/dependencies.rb:67:in `resolve_dependency'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:23:in `block in initialize'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:59:in `resolve_dependency'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:268:in `block in resolve_dependencies'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:268:in `map'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:268:in `resolve_dependencies'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:55:in `block in load'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:311:in `block in fetch_asset_from_dependency_cache'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:307:in `each'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:307:in `each_with_index'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:307:in `fetch_asset_from_dependency_cache'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in `load'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in `load'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in `find_asset'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:134:in `block in find'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:133:in `each'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:133:in `find'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in `compile'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:67:in `block (3 levels) in define'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in `with_logger'
remote:        /tmp/build_fbac64d9/vendor/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:66:in `block (2 levels) in define'
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

这是我的宝石档案

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

ruby "2.5.7"
gem 'rails', '5.2.4.3'
gem 'puma', '~> 3.12'
gem 'sdoc', '~> 0.4.0', group: :doc
gem "devise", ">= 4.7.1"
gem 'devise_token_auth'
gem 'activeadmin'
gem "paperclip"
gem 'aws-sdk'
gem 'dotenv-rails', :groups => [:development, :test]
gem 'bower-rails', '~> 0.11.0'
gem 'mysql2'
gem 'uglifier'
gem 'active_model_serializers', '~> 0.10.4'
gem 'nexmo', '4.8'
gem 'descriptive_statistics', '2.5.1'

# This is only for development mode, but Heroku always bundles the production group,
# so we need this here in case we're running Rails in development mode
gem 'listen', '>= 3.0.5', '< 3.2'

group :development, :test do
  # Use sqlite3 as the database for Active Record
  gem 'sqlite3'
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '~> 2.13'
  gem 'selenium-webdriver'
  gem 'rb-readline'

end

group :development do
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test  do
    gem 'timecop'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

我搜索并找到了一些与链轮和sassc gem相关的similar issues,但我没有加载该gem,所以我不知道该如何处理这些信息。

bq9c1y66

bq9c1y661#

要使用带链轮的sass,您需要sass-rails gem。将此添加到您的gem文件中:

gem 'sass-rails'
jpfvwuh4

jpfvwuh42#

最后我把gem 'sassc-rails'添加到我的Gemfile中。我猜codenamev的建议可能也会起作用,因为潜在的问题似乎涉及到遗留项目中缺少依赖项。更多信息请点击此处:https://github.com/sass/sassc-rails/issues/114

p1iqtdky

p1iqtdky3#

生产中添加.rb

config.assets.css_compressor = :yui
config.assets.js_compressor = :terser

及添设了

gem 'sassc-rails'

这对我有用。

相关问题