运行rake assets:precompile
以错误结束。找不到为什么它仍然需要sassc,当sassc使用从sprockets 3.x升级到4.x:的指南迁移到链轮4时,它只在项目中
gem 'sass-rails', '>= 5'
bundle update sass-rails sprockets
然后按照dartsassrails安装文档。完成:
rails tmp:clear
rake assets:clobber
rake assets:precompile
ruby-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
并重新启动服务器来修复它;我的assets.rb文件中没有包含任何文件,当我运行时,这种情况也开始发生在我身上
$ rails importmap:install
$ rails turbo:install stimulus:install
发现问题:在样式表下,根文件夹是额外的example.scss
文件,它被设置为使用预编译
Rails.application.config.assets.precompile += %w( example.css )
显示此错误是因为文件实际具有不同的扩展名。
解决方案:
- 从预编译中取出example.css
- 为dartsas添加了文件以使用以下方法处理它:
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中,默认配置是不在开发环境中提取scs。您需要在config/webpacker.yml
中打开此选项。
development:
<<: *default
compile: true
extract_css: true
我不知道为什么链轮会出现这种情况,但其他人可能也有和我一样的问题,希望这能帮助他们。
我在使用jsbundling和cssbundling(而不是importmaps(的Rails 7中遇到了这个问题。这是由一些名称冲突的文件引起的。我在assets文件夹中有自己的slimselect.css文件,但也从"slimselect"npm包中导入了slimselect-css。
重命名我自己的文件为我修复了它。
我想在这里提到它,因为上面的解决方案都不起作用,而且显然这个错误有很多不同的原因。
这里的许多答案都朝着完全不同的方向发展——在我看来,这很好地代表了Rails资产管道。
以下是对我有效的
在manifest.js
中
//= link_tree ../stylesheets .css
样式表文件夹同时包含scs和css。取而代之的是,对scss文件使用link_tree,对css文件使用link。
//= link_tree ../stylesheets .scss
//= link other.css
//= link another.css