运行
rake assets:precompile
以错误结束。
找不到为什么它仍然需要 sassc,sassc 仅在使用 从 Sprockets 3.x 升级到 4.x 的指南迁移到 sprockets 4 时才在项目中:
gem 'sass-rails', '>= 5'
bundle update sass-rails sprockets
然后按照 dartsass-rails 安装文档进行操作。 做了:
rails tmp:clear
rake assets:clobber
rake assets:precompile
红宝石-3.1.2
gem 'rails', '7.0.3.1'
gem 'webrick'
gem 'sprockets-rails', '~> 3.4', '>= 3.4.2'
gem 'dartsass-rails', '~> 0.4.0'
...
manifest.js 文件内容:
//= link_tree ../images
//= link application.css
//= link application.js
//
//= link_tree ../builds
错误日志:
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke dartsass:build (first_time)
** Invoke environment
** Execute dartsass:build
+ /.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/dartsass-rails-0.4.0/exe/darwin/sass --style\=compressed --no-source-map --load-path
/app/assets/stylesheets --load-path
/app/assets/builds --load-path
/app/assets/config --load-path
/app/assets/fonts --load-path
/app/assets/images --load-path
/app/assets/javascripts --load-path
/app/assets/stylesheets --load-path
/lib/assets/javascripts --load-path
/lib/assets/stylesheets --load-path
/vendor/assets/javascripts --load-path
/vendor/assets/stylesheets --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/flex_calendar-aae0ac1c9b3f/app/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/flex_calendar-aae0ac1c9b3f/app/assets/images --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/flex_calendar-aae0ac1c9b3f/app/assets/stylesheets --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/flex_calendar-aae0ac1c9b3f/lib/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/flatpickr-4.5.7.0/vendor/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/flex_calendar-aae0ac1c9b3f/vendor/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/flatpickr-4.5.7.0/vendor/assets/stylesheets --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/tinymce-rails-5.10.5/app/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/tinymce-rails-5.10.5/app/assets/source --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/tinymce-rails-5.10.5/vendor/assets/config --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jquery-minicolors-rails-2.2.6.2/vendor/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/tinymce-rails-5.10.5/vendor/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jquery-minicolors-rails-2.2.6.2/vendor/assets/stylesheets --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/select2-rails-4.0.13/vendor/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/select2-rails-4.0.13/vendor/assets/stylesheets --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jquery-ui-rails-5.0.5/app/assets/images --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jquery-ui-rails-5.0.5/app/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jquery-ui-rails-5.0.5/app/assets/stylesheets --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jquery-rails-4.2.1/vendor/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/coffee-rails-5.0.0/lib/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/actiontext-7.0.3.1/app/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/actiontext-7.0.3.1/app/assets/stylesheets --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/actioncable-7.0.3.1/app/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activestorage-7.0.3.1/app/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/actionview-7.0.3.1/lib/assets/compiled --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/react-rails-1.9.0/lib/assets/react-source/development --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/react-rails-1.9.0/lib/assets/javascripts/ --load-path
/app/assets/fonts
/app/assets/stylesheets/application.scss:
/app/assets/builds/application.css
** Execute assets:precompile
rake aborted!
LoadError: cannot load such file -- sassc
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/autoload/sassc.rb:2:in `<top (required)>'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/sassc_processor.rb:42:in `initialize'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/sassc_processor.rb:27:in `new'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/sassc_processor.rb:27:in `instance'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/sassc_processor.rb:31:in `call'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:84:in `call_processor'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:65:in `call_processors'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:22:in `block in <class:CompositeProcessor>'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:33:in `call'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:84:in `call_processor'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:65:in `call_processors'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:182:in `load_from_unloaded'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:59:in `block in load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:43:in `load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/cached_environment.rb:44:in `block in load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/cached_environment.rb:44:in `fetch'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/cached_environment.rb:44:in `load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/bundle.rb:27:in `call'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:84:in `call_processor'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:65:in `call_processors'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:182:in `load_from_unloaded'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:59:in `block in load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:43:in `load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/cached_environment.rb:44:in `block in load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/cached_environment.rb:44:in `fetch'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/cached_environment.rb:44:in `load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/base.rb:81:in `find_asset'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/base.rb:88:in `find_all_linked_assets'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/manifest.rb:125:in `each'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/manifest.rb:125:in `to_a'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/manifest.rb:125:in `block (2 levels) in find'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `block in synchronize'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:22:in `execute'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/promise.rb:564:in `block in realize'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:352:in `run_task'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:343:in `block (3 levels) in create_worker'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `loop'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `block (2 levels) in create_worker'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:333:in `catch'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:333:in `block in create_worker'
Tasks: TOP => assets:precompile
操作系统:mac
当我安装依赖于 sassc-rails 的 gem(例如 pdfjs_viewer-rails)并使用
./bin/dev
启动服务器时,Web 启动并正常工作。
问题: 知道这可能是什么原因以及可能的解决方案吗?
我通过运行
rails tmp:clear
并重新启动服务器来修复它;我没有在我的 asset.rb 文件中包含任何文件,当我运行时,这也开始发生在我身上:
$ rails importmap:install
$ rails turbo:install stimulus:install
发现问题: 由于样式表根文件夹下有额外的
example.scss
文件,并且它被设置为预编译:
Rails.application.config.assets.precompile += %w( example.css )
显示此错误是因为文件实际上具有不同的扩展名。
解决方案:
Rails.application.config.dartsass.builds = {
"application.scss" => "application.css",
"example.scss" => "example.css"
}
将 better_errors gem 升级到版本 2.10.0 也会导致该错误,至少在 Rails 7 中是这样(请参阅 https://github.com/BetterErrors/better_errors/issues/516)。
解决方法是通过类似
之类的方式阻止使用此特定版本gem 'better_errors', '!= 2.10.0'
我也遇到过这个问题。通过搜索
cannot load such file -- sass
来到了这个帖子。
我知道你正在使用链轮,但我在使用 webpacker 时遇到了这个错误。
在webpacker中,默认配置是在开发环境中不提取scss。 您需要在
config/webpacker.yml
中打开此功能。
development:
<<: *default
compile: true
extract_css: true
我不知道为什么链轮会发生这种情况,但其他人可能也有和我一样的问题,希望这对他们有帮助。
我在 Rails 7 中使用 jsbundling 和 cssbundling(不是 importmaps)遇到了这个问题。这是由一些名称冲突的文件引起的。我在 asset 文件夹中有自己的 slimselect.scss 文件,而且还从“slimselect”npm 包中导入了 slimselect css。
重命名我自己的文件为我解决了这个问题。
我想在这里提到它,因为上述解决方案都不起作用,而且显然导致此错误的原因有很多不同。
这里的许多答案都朝着完全不同的方向发展 - 在我看来,这很好地代表了 Rails 资产管道。
这对我有用
在
manifest.js
//= link_tree ../stylesheets .css
stylesheets文件夹包含scss和css。相反,有效的方法是对 scss 文件使用 link_tree,对 css 文件使用 link。
//= link_tree ../stylesheets .scss
//= link other.css
//= link another.css