(Rails 5) LoadError: 无法加载此类文件 -- sass ...部署到 Heroku 时

eme*_*his 11 ruby ruby-on-rails heroku gemfile

当我部署 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

Run Code Online (Sandbox Code Playgroud)

这是我的 Gemfile

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]
Run Code Online (Sandbox Code Playgroud)

我有什么想法可以解决这个问题吗?我搜索并发现了一些与 Sprockets 和 sassc gem 相关的类似问题,但我没有加载该 gem,所以我不确定该信息在哪里。

cod*_*mev 27

要将 sass 与 sprocket 一起使用,您\xe2\x80\x99 需要 sass-rails gem。将其添加到您的 Gemfile 中:

\n
gem 'sass-rails'\n
Run Code Online (Sandbox Code Playgroud)\n


eme*_*his 3

最终对我有用的是添加gem 'sassc-rails'到我的 Gemfile 中。我猜 codenamev 的建议也可能有效,因为潜在的问题似乎涉及遗留项目中缺少依赖项。更多信息在这里:https://github.com/sass/sassc-rails/issues/114