ruby-on-rails - Heroku : `SassC::SyntaxError: Error: Undefined variable: "$body-bg"` 上的 Rails 6

标签 ruby-on-rails heroku sass sass-rails

从 Rails 5 升级到 Rails 6.0.3.1 后,我的 SCSS 无法在 Heroku 上编译:

remote:        yarn install v1.16.0
remote:        [1/4] Resolving packages...
remote:        [2/4] Fetching packages...
remote:        info fsevents@1.1.3: The platform "linux" is incompatible with this module.
remote:        info "fsevents@1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
remote:        [3/4] Linking dependencies...
remote:        warning "@rails/webpacker > postcss-cssnext@3.1.0" has unmet peer dependency "caniuse-lite@^1.0.30000697".
remote:        warning " > webpack-dev-server@2.11.2" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
remote:        warning "webpack-dev-server > webpack-dev-middleware@1.12.2" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
remote:        [4/4] Building fresh packages...
remote:        Done in 5.09s.
remote:        rake aborted!
remote:        SassC::SyntaxError: Error: Undefined variable: "$body-bg".
remote:                on line 22:21 of app/assets/stylesheets/override_darkmode.scss
remote:        >>   background-color: $body-bg;
remote:
remote:           --------------------^
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/app/assets/stylesheets/override_darkmode.scss:22
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sassc-2.4.0/lib/sassc/engine.rb:50:in `render'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sassc-rails-2.1.2/lib/sassc/rails/template.rb:40:in `block in call'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/utils.rb:138:in `module_include'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sassc-rails-2.1.2/lib/sassc/rails/template.rb:39:in `call'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84:in `call_processor'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `reverse_each'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `call_processors'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:22:in `block in <class:CompositeProcessor>'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:33:in `call'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84:in `call_processor'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `reverse_each'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `call_processors'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:182:in `load_from_unloaded'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:59:in `block in load'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:43:in `load'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/cached_environment.rb:44:in `load'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/bundle.rb:27:in `call'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84:in `call_processor'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `reverse_each'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `call_processors'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:182:in `load_from_unloaded'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:59:in `block in load'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:43:in `load'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/cached_environment.rb:44:in `load'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/bundle.rb:32:in `block in call'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/bundle.rb:31:in `call'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84:in `call_processor'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `reverse_each'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `call_processors'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:182:in `load_from_unloaded'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:59:in `block in load'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:43:in `load'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/cached_environment.rb:44:in `load'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/base.rb:81:in `find_asset'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/base.rb:88:in `find_all_linked_assets'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/manifest.rb:125:in `block (2 levels) in find'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:41:in `block in synchronize'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:41:in `synchronize'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:41:in `synchronize'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:19:in `execute'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/promise.rb:563:in `block in realize'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:353:in `run_task'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:342:in `block (3 levels) in create_worker'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:325:in `loop'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:325:in `block (2 levels) in create_worker'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:324:in `catch'
remote:        /tmp/build_2fccbc688d4b92273fdbd9ffef333655/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:324:in `block in create_worker'
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.

override_darkmode.scss:

input {
  background-color: $body-bg;
}

application-dark.scss:

$body-bg: #2d2d2d;

@import 'override_darkmode';

我使用 gem :

gem 'sass-rails', '>= 6'
gem 'bootstrap-sass'

已解决:

    bootstrap-sass (3.4.1)
      autoprefixer-rails (>= 5.2.1)
      sassc (>= 2.0.0)
    sass-rails (6.0.0)
      sassc-rails (~> 2.1, >= 2.1.1)
    sassc (2.4.0)
    sassc-rails (2.1.2)
      sassc (>= 2.0)

更新:在 rake assets:clean 之后,出现不同的错误:Segmentation Fault:

remote:        [4/4] Building fresh packages...
remote:        Done in 5.26s.
remote:        /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sassc-2.4.0/lib/sassc/engine.rb:43: [BUG] Segmentation fault at 0x0000000000000000
remote:        ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
remote:
remote:        -- Control frame information -----------------------------------------------
remote:        c:0059 p:---- s:0449 e:000448 CFUNC  :compile_data_context
remote:        c:0058 p:0318 s:0444 e:000443 METHOD /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sassc-2.4.0/lib/sassc/engine.rb:43
remote:        c:0057 p:0006 s:0432 e:000431 BLOCK  /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sassc-rails-2.1.2/lib/sassc/rails/template.rb:40
remote:        c:0056 p:0028 s:0429 e:000428 METHOD /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/utils.rb:138
remote:        c:0055 p:0164 s:0422 e:000421 METHOD /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sassc-rails-2.1.2/lib/sassc/rails/template.rb:39
remote:        c:0054 p:0053 s:0413 e:000412 METHOD /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84
remote:        c:0053 p:0016 s:0405 e:000404 BLOCK  /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:66 [FINISH]
remote:        c:0052 p:---- s:0400 e:000399 CFUNC  :reverse_each
remote:        c:0051 p:0039 s:0396 e:000395 METHOD /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65
remote:        c:0050 p:0015 s:0388 e:000387 BLOCK  /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:22
remote:        c:0049 p:0013 s:0383 e:000382 METHOD /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:33
remote:        c:0048 p:0053 s:0378 e:000377 METHOD /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84
remote:        c:0047 p:0016 s:0370 e:000369 BLOCK  /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:66 [FINISH]
remote:        c:0046 p:---- s:0365 e:000364 CFUNC  :reverse_each
remote:        c:0045 p:0039 s:0361 e:000360 METHOD /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65
remote:        c:0044 p:0476 s:0353 e:000352 METHOD /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:182
remote:        c:0043 p:0073 s:0331 e:000330 BLOCK  /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:59
remote:        c:0042 p:0038 s:0325 e:000324 METHOD /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:337
remote:        c:0041 p:0157 s:0315 e:000314 METHOD /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:43
remote:        c:0040 p:0022 s:0306 e:000302 METHOD /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/cached_environment.rb:4
remote:        c:0039 p:0111 s:0298 e:000297 METHOD /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/bundle.rb:27
remote:        c:0038 p:0053 s:0280 e:000279 METHOD /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84
remote:        c:0037 p:0016 s:0272 e:000271 BLOCK  /tmp/build_b13f5fdf4f65289fdc5aa3d30752d7e5/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:66 [FINISH]
remote:        c:0036 p:---- s:0267 e:000266 CFUNC  :reverse_each
remote:        c:0035 p:0039 s:0263 e:000262 METHOD 
...

相关:https://github.com/sass/sassc-rails/issues/122

最佳答案

已通过删除 config 文件中的所有 config.assets.precompile 调用并改用 app/assets/config/manifest.js 来修复。

cf https://github.com/rails/sprockets/blob/8fc492abde6b20afbe6fa5d5aa7d1085aafd3527/UPGRADING.md#manifestjs

关于ruby-on-rails - Heroku : `SassC::SyntaxError: Error: Undefined variable: "$body-bg"` 上的 Rails 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62233567/

相关文章:

ruby - 尝试加载 gem 'pry-rails' 时出错

html - CSS相邻选择器不起作用

ruby-on-rails - ActiveRecord 错误问题

ruby-on-rails - 将 gmaps4rails 与 Active Admin 一起使用,没有 map

ruby-on-rails - 为什么 Ruby 只在我的系统上抛出一个段错误,而且只在这个 Rails 应用程序中?

html - 如何使用 Sass 获取动态列表中的项目数?

html - Sass 和关键帧

ruby-on-rails - 在 Rails 中创建应用程序后添加外键

python - 如何在不使用 Djstatic 和 Whitenoise 的情况下添加静态文件?

python-2.7 - 在heroku上部署scrapy项目