Heroku 的 Rails 7 项目中未生成 tailwind.css

pup*_*eno 13 ruby-on-rails tailwind-css ruby-on-rails-7

tailwind.css我有一个使用 TailwindCSS 部署到 Heroku 的 Rails 7 项目,该项目在期间没有构建rake asset:precompile,我不知道为什么。当我尝试访问该应用程序时,它崩溃并出现以下错误:

I, [2022-03-23T17:35:18.429029 #8]  INFO -- : [4f6eaac8-942c-4ee5-af10-172663b1a292] Started GET "/" for XX.XX.XX.XX at 2022-03-23 17:35:18 +0000
I, [2022-03-23T17:35:18.433526 #8]  INFO -- : [4f6eaac8-942c-4ee5-af10-172663b1a292] Processing by StaticController#index as HTML
I, [2022-03-23T17:35:18.439133 #8]  INFO -- : [4f6eaac8-942c-4ee5-af10-172663b1a292]   Rendered static/index.html.erb within layouts/application (Duration: 0.6ms | Allocations: 184)
I, [2022-03-23T17:35:18.446294 #8]  INFO -- : [4f6eaac8-942c-4ee5-af10-172663b1a292]   Rendered layout layouts/application.html.erb (Duration: 7.8ms | Allocations: 1205)
I, [2022-03-23T17:35:18.446595 #8]  INFO -- : [4f6eaac8-942c-4ee5-af10-172663b1a292] Completed 500 Internal Server Error in 13ms (Allocations: 2512)
F, [2022-03-23T17:35:18.447716 #8] FATAL -- : [4f6eaac8-942c-4ee5-af10-172663b1a292]
[4f6eaac8-942c-4ee5-af10-172663b1a292] ActionView::Template::Error (The asset "tailwind.css" is not present in the asset pipeline.
):
[4f6eaac8-942c-4ee5-af10-172663b1a292]     12:     <meta name="theme-color" content="#ffffff">
[4f6eaac8-942c-4ee5-af10-172663b1a292]     13:     <%= csrf_meta_tags %>
[4f6eaac8-942c-4ee5-af10-172663b1a292]     14:     <%= csp_meta_tag %>
[4f6eaac8-942c-4ee5-af10-172663b1a292]     15:     <%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %>
[4f6eaac8-942c-4ee5-af10-172663b1a292]     16:     <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
[4f6eaac8-942c-4ee5-af10-172663b1a292]     17:     <%= javascript_importmap_tags %>
[4f6eaac8-942c-4ee5-af10-172663b1a292]     18:   </head>
[4f6eaac8-942c-4ee5-af10-172663b1a292]
[4f6eaac8-942c-4ee5-af10-172663b1a292] app/views/layouts/application.html.erb:15
Run Code Online (Sandbox Code Playgroud)

实际上,我有两个项目的设置几乎相同(尽管它们具有不同的功能),另一个项目可以工作。

我已经添加了

I, [2022-03-23T17:35:18.429029 #8]  INFO -- : [4f6eaac8-942c-4ee5-af10-172663b1a292] Started GET "/" for XX.XX.XX.XX at 2022-03-23 17:35:18 +0000
I, [2022-03-23T17:35:18.433526 #8]  INFO -- : [4f6eaac8-942c-4ee5-af10-172663b1a292] Processing by StaticController#index as HTML
I, [2022-03-23T17:35:18.439133 #8]  INFO -- : [4f6eaac8-942c-4ee5-af10-172663b1a292]   Rendered static/index.html.erb within layouts/application (Duration: 0.6ms | Allocations: 184)
I, [2022-03-23T17:35:18.446294 #8]  INFO -- : [4f6eaac8-942c-4ee5-af10-172663b1a292]   Rendered layout layouts/application.html.erb (Duration: 7.8ms | Allocations: 1205)
I, [2022-03-23T17:35:18.446595 #8]  INFO -- : [4f6eaac8-942c-4ee5-af10-172663b1a292] Completed 500 Internal Server Error in 13ms (Allocations: 2512)
F, [2022-03-23T17:35:18.447716 #8] FATAL -- : [4f6eaac8-942c-4ee5-af10-172663b1a292]
[4f6eaac8-942c-4ee5-af10-172663b1a292] ActionView::Template::Error (The asset "tailwind.css" is not present in the asset pipeline.
):
[4f6eaac8-942c-4ee5-af10-172663b1a292]     12:     <meta name="theme-color" content="#ffffff">
[4f6eaac8-942c-4ee5-af10-172663b1a292]     13:     <%= csrf_meta_tags %>
[4f6eaac8-942c-4ee5-af10-172663b1a292]     14:     <%= csp_meta_tag %>
[4f6eaac8-942c-4ee5-af10-172663b1a292]     15:     <%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %>
[4f6eaac8-942c-4ee5-af10-172663b1a292]     16:     <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
[4f6eaac8-942c-4ee5-af10-172663b1a292]     17:     <%= javascript_importmap_tags %>
[4f6eaac8-942c-4ee5-af10-172663b1a292]     18:   </head>
[4f6eaac8-942c-4ee5-af10-172663b1a292]
[4f6eaac8-942c-4ee5-af10-172663b1a292] app/views/layouts/application.html.erb:15
Run Code Online (Sandbox Code Playgroud)

production.rbtest.rbdevelopment.rb(以防万一)。

tailwindcss-rails在撰写本文时,我正在安装最新版本2.0.8。我也正在安装,sassc-rails因为它是需要的,rails_admin但对于需要它的其他项目来说也是如此。

这是奇怪的事情。如果我打开 Heroku 项目的控制台并运行它,rake asset:precompile它实际上完成了丢失文件的创建:

~ $ rake assets:precompile
+ /app/vendor/bundle/ruby/3.1.0/gems/tailwindcss-rails-2.0.8-x86_64-linux/exe/x86_64-linux/tailwindcss -i /app/app/assets/stylesheets/application.tailwind.css -o /app/app/assets/builds/tailwind.css -c /app/config/tailwind.config.js --minify

Done in 821ms.
W, [2022-03-19T12:38:43.514430 #6]  WARN -- : Removed sourceMappingURL comment for missing asset 'rails_admin/popper.js.map' from /app/vendor/bundle/ruby/3.1.0/gems/rails_admin-3.0.0.rc4/vendor/assets/javascripts/rails_admin/popper.js
W, [2022-03-19T12:38:43.534443 #6]  WARN -- : Removed sourceMappingURL comment for missing asset 'rails_admin/bootstrap.js.map' from /app/vendor/bundle/ruby/3.1.0/gems/rails_admin-3.0.0.rc4/vendor/assets/javascripts/rails_admin/bootstrap.js
I, [2022-03-19T12:38:43.744157 #6]  INFO -- : Writing /app/public/assets/tailwind-0c01c3e907ab268dbd4dcaa14542a12d0388cfbeb5733a183e88e1b26ef30afb.css
I, [2022-03-19T12:38:43.744385 #6]  INFO -- : Writing /app/public/assets/tailwind-0c01c3e907ab268dbd4dcaa14542a12d0388cfbeb5733a183e88e1b26ef30afb.css.gz
~ $
Run Code Online (Sandbox Code Playgroud)

为什么在部署期间不起作用?我可以看到它正在运行:

       Using stimulus-rails 1.0.4
       Using tailwindcss-rails 2.0.8 (x86_64-linux)
       Bundle complete! 28 Gemfile dependencies, 90 gems now installed.
       Gems in the groups 'development' and 'test' were not installed.
       Bundled gems are installed into `./vendor/bundle`
       Bundle completed (0.38s)
       Cleaning up the bundler cache.
       Removing bundler (2.2.33)
-----> Detecting rake tasks
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       
       Done in 788ms.
       Asset precompilation completed (3.58s)
       Cleaning assets
       Running: rake assets:clean
-----> Detecting rails configuration
-----> Discovering process types
       Procfile declares types     -> release, web, worker
       Default types for buildpack -> console, rake
-----> Compressing...
       Done: 78.7M
-----> Launching...
Run Code Online (Sandbox Code Playgroud)

pup*_*eno 19

我发现了问题:

在某些时候,我app/assets/builds/.keep从项目中删除了该项目,这导致app/assets/buildgit 克隆存储库时无法创建目录。我不明白为什么这会导致tailwind.css在第一次运行时不创建,但它是在第二次运行时创建的rake assets:precompile

将其报告为错误以防万一:https ://github.com/rails/tailwindcss-rails/issues/158


Jig*_*att 7

Rails 资产:干净资产:预编译

这个命令已解决帮助我解决了这个问题。