Heroku 的 Rails 7 项目中未生成 tailwind.css
我有一个使用 TailwindCSS 部署到 Heroku 的 Rails 7 项目,该项目在 rake asset:precompile
期间没有构建 tailwind.css
,我不知道为什么。当我尝试访问该应用程序时,它因以下错误而崩溃:
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
实际上,我有两个设置几乎相同的项目(尽管它们具有不同的功能),而另一个项目可以工作。
我已添加
config.assets.css_compressor = nil
到 development.rb
、test.rb
和 development.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
~ $
为什么在部署期间不起作用?我可以看到它正在运行:
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...
I have a Rails 7 project using TailwindCSS deployed to Heroku that is not building tailwind.css
during rake asset:precompile
and I don't know why. When I try to access the application, it crashes with this error:
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
I actually have two projects that are set up pretty much identically (they have different functionality though) and the other one works.
I have added
config.assets.css_compressor = nil
to production.rb
, test.rb
and development.rb
(just in case).
I'm installing the latest tailwindcss-rails
at the time of this writing, 2.0.8. I'm also installing sassc-rails
because it's needed for rails_admin
but that's also true for the other project where that is needed.
Here's the curious thing. If I open a console to that Heroku project and run rake asset:precompile
it actually finishes creating the missing files:
~ $ 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
~ $
Why didn't that work during deployment? I can see it's running it:
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试在本地计算机上运行以下命令:
然后提交这些更改并再次部署。
Try running the following commands on your local machine:
Then commit these changes, and deploy again.
对于再次遇到此问题的任何人,只需在 config/environments/development.rb 中设置以下内容并重新启动服务器
即可,它会发现您在开发中遇到的任何资产问题,并提供一些建议如何修复它们。
如果您修复了它报告的问题,那么您在生产中也不会有任何资产问题! (是的,它还会报告您在产品中遇到的任何潜在问题)
For anyone who faces this problem again, just set the following in your
config/environments/development.rb
and restart the serverWhat this does is it uncovers any asset issues you have in development, with some suggestions on how to fix them.
If you fix the issues it reports, you won't have any asset issues in production as well! (yes, it also reports any potential issues you will have in prod)
我发现了问题:
在某个时候,我从项目中删除了
app/assets/builds/.keep
,这导致 git 时不会创建app/assets/build
目录克隆存储库。我不明白为什么这会导致tailwind.css
在第一次运行时未创建,但它是在第二次运行rake asset:precompile
时创建的。将其报告为错误,以防万一: https://github.com/rails/tailwindcss-导轨/问题/158
I found the problem:
At some point I removed
app/assets/builds/.keep
from the project which causes theapp/assets/build
directory to not be created when git cloning the repo. I don't understand why that causestailwind.css
to not be created on the first run, but it is created on the second run ofrake assets:precompile
.Reported it as a bug just in case: https://github.com/rails/tailwindcss-rails/issues/158
此命令已解决帮助我解决了此问题。
this command resolved helped me to resolved this issue.