6

我正在努力将一个新的 Rails 7 项目部署到生产中(在 Heroku 和 Render.com 上尝试),并且在构建过程中出现以下错误:

$ tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css

       Done in 408ms.
       Done in 0.90s.
       rake aborted!
       SassC::SyntaxError: Error: Function rgb is missing argument $green.
               on line 428 of stdin
       >>   color: rgb(29 78 216 / var(--tw-text-opacity));

          ---------^
       stdin:428

这就是我认为相关的部分,但如果有帮助,这里有更多的输出上下文。

Preparing app for Rails asset pipeline
       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...
       Done in 5.10s.
       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.10s.
       yarn install v1.22.17
       [1/4] Resolving packages...
       success Already up-to-date.
       Done in 0.12s.
       yarn run v1.22.17
       $ tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css
       
       Done in 408ms.
       Done in 0.90s.
       rake aborted!
       SassC::SyntaxError: Error: Function rgb is missing argument $green.
               on line 428 of stdin
       >>   color: rgb(29 78 216 / var(--tw-text-opacity));
       
          ---------^
       stdin:428
       /tmp/build_d9d0bde2/vendor/bundle/ruby/3.0.0/gems/sassc-2.4.0/lib/sassc/engine.rb:50:in `render'
       /tmp/build_d9d0bde2/vendor/bundle/ruby/3.0.0/gems/sassc-rails-2.1.2/lib/sassc/rails/compressor.rb:29:in `call'
       /tmp/build_d9d0bde2/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/sass_compressor.rb:30:in `call'
       /tmp/build_d9d0bde2/vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84:in `call_processor'

我使用rails new project_name -j esbuild --css tailwind. 开发模式工作正常,只是生产部署。

我不确定从哪里开始调试它。

4

3 回答 3

7

防止 sassc-rails 将 sass 设置为压缩机为我修复它。

将此添加到 application.rb

config.assets.css_compressor = nil

于 2022-01-11T11:06:45.317 回答
2

从 Rails 顺风自述文件

Tailwind 使用了 sassc-rails 扩展无法识别的现代 CSS 功能,该扩展默认包含在 Rails 6 的 Gemfile 中。为了避免像 SassC::SyntaxError 这样的错误,您必须从 Gemfile 中删除该 gem。

https://github.com/rails/tailwindcss-rails

于 2021-12-18T05:58:04.233 回答
0

与文森特的回答类似,我输入config.assets.css_compressor = nilconfig/environments/production.rb. 把它放进去application.rb没有用。

我还sassc-rails安装了 gem

于 2022-02-19T03:31:40.877 回答