assets:precompile 导致 LoadError: cannot load such file -- sassc

Posted

技术标签:

【中文标题】assets:precompile 导致 LoadError: cannot load such file -- sassc【英文标题】:assets:precompile results in LoadError: cannot load such file -- sassc 【发布时间】:2022-01-21 04:38:19 【问题描述】:

使用esbuildtailwind 的新Rails 7 应用程序。

当我运行 rake assets:precompile 时,我收到此错误:LoadError: cannot load such file -- sassc

我删除了sassc-rails gem due a SaasC syntax error。

这是本地预编译的完整输出...

rake assets:precompile
yarn install v1.22.15
[1/4] ????  Resolving packages...
success Already up-to-date.
✨  Done in 0.06s.
yarn run v1.22.15
$ esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds

  app/assets/builds/application.js      185.5kb
  app/assets/builds/application.js.map  301.0kb

✨  Done in 0.13s.
yarn install v1.22.15
[1/4] ????  Resolving packages...
success Already up-to-date.
✨  Done in 0.06s.
yarn run v1.22.15
$ tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css

Done in 155ms.
✨  Done in 0.52s.
rake aborted!
LoadError: cannot load such file -- sassc

Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

这是 Heroku 的输出...

Running: rake assets:precompile
       yarn install v1.22.17
       [1/4] Resolving packages...
       [2/4] Fetching packages...
       [3/4] Linking dependencies...
       [4/4] Building fresh packages...
       success Saved lockfile.
       Done in 4.39s.
       yarn run v1.22.17
       $ esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds
       
         app/assets/builds/application.js      185.5kb
         app/assets/builds/application.js.map  301.0kb
       
       Done in 0.11s.
       yarn install v1.22.17
       [1/4] Resolving packages...
       success Already up-to-date.
       Done in 0.13s.
       yarn run v1.22.17
       $ tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css
       
       Done in 440ms.
       Done in 0.99s.
       rake aborted!
       LoadError: cannot load such file -- sassc
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:34:in `require'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/zeitwerk-2.5.1/lib/zeitwerk/kernel.rb:35:in `require'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/autoload/sassc.rb:2:in `<main>'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/zeitwerk-2.5.1/lib/zeitwerk/kernel.rb:35:in `require'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/sassc_processor.rb:42:in `initialize'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/sassc_processor.rb:27:in `new'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/sassc_processor.rb:27:in `instance'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/sassc_processor.rb:31:in `call'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84:in `call_processor'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `reverse_each'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `call_processors'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:22:in `block in <class:CompositeProcessor>'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:33:in `call'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84:in `call_processor'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `reverse_each'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `call_processors'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:182:in `load_from_unloaded'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:59:in `block in load'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:43:in `load'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/cached_environment.rb:44:in `load'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/bundle.rb:27:in `call'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84:in `call_processor'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `reverse_each'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `call_processors'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:182:in `load_from_unloaded'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:59:in `block in load'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:43:in `load'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/cached_environment.rb:44:in `load'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/base.rb:81:in `find_asset'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/base.rb:88:in `find_all_linked_assets'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/manifest.rb:125:in `block (2 levels) in find'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `block in synchronize'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:19:in `execute'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/promise.rb:564:in `block in realize'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:363:in `run_task'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:352:in `block (3 levels) in create_worker'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:335:in `loop'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:335:in `block (2 levels) in create_worker'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `catch'
       /tmp/build_7c167d00/vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `block in create_worker'
       Tasks: TOP => assets:precompile
       (See full trace by running task with --trace)

不知道还能在这里尝试什么。

【问题讨论】:

同样的问题 - 同时又添加了 'sass-rails' 【参考方案1】:

我今天遇到了同样的问题,并通过清除 Heroku 构建缓存 (instructions here) 在 Heroku 端解决了它

heroku plugins:install heroku-builds

heroku builds:cache:purge -a example-app

【讨论】:

谢谢!它也对我有用。【参考方案2】:

我有同样的问题并通过以下方式解决。

app/assets/stylesheets/* 中的所有 .scss 到 .css (如果你在 .scss 文件中写过@import ...,请修复为*= require ... $ bundle clean

就我而言,我猜是因为我在顺风之前使用过引导程序,所以关于引导程序的 .scss 文件一直保留在供应商/捆绑包中。

【讨论】:

当我安装其他 gem 并且没有被 $ bundle clean 解决时,我再次遇到了同样的问题。所以,我试了$ rails tmp:clear,问题已经解决了。

以上是关于assets:precompile 导致 LoadError: cannot load such file -- sassc的主要内容,如果未能解决你的问题,请参考以下文章

rake assets:precompile 试图连接到生产数据库?

rake assets:precompile 突然失败

在 Rails 中使用 config.assets.precompile 在子目录中包含资产

在'rake assets:precompile'之后,Rails 4 资产未加载到 Heroku

在 bundle exec rake assets:precompile 后 OpsWorks 部署失败

Capistrano - rake assets:precompile - 应用程序已经初始化