administrate: sassc dependency breaks compatibility with tailwindcss-rails
- What were you trying to do?
I’m trying to use tailwind-rails v2.0.2 and importmaps.
- What did you end up with (logs, or, even better, example apps are great!)?
I’m getting a SassC::SyntaxError
when I run rake assets:precompile
. Based on my debugging, it’s because tailwind-rails
is incompatible with the sassc-rails
gem that administrate requires as a dependency:
Tailwind uses modern CSS features that are not recognized by the sassc-rails extension that was included by default in the Gemfile for Rails 6. In order to avoid any errors like SassC::SyntaxError, you must remove that gem from your Gemfile.
- What versions are you running?
Rails 7.0 Administrate 0.16.0
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 16
- Comments: 25 (9 by maintainers)
Commits related to this issue
- Merge tag '0.0.3.1' into develop dependency bugfix https://github.com/thoughtbot/administrate/issues/2091 — committed to charliezh4ng/charlie_zhang_live by charles-the-meathead 2 years ago
- Fix RSpec part of build to compile assets seems that Administrate depends on SassC compression which does not work with TailwindCSS and so implemented the fix from https://github.com/thoughtbot/adm... — committed to failure-driven/pair-with-me by saramic 2 years ago
- :bug: fix assets compilation failing in prod Assets compilation was failing because tailwind css is trying to be compressed by sassc. Read: https://github.com/thoughtbot/administrate/issues/2091 I h... — committed to AlejandroMI/wibio by AlejandroMI a year ago
What I did for some projects which still depend on Sass was creating my own compressor, which skips the SassC compression if it fails.
Since the skipped (tailwind) files, are not compressed this way, I just added the
--minify
option to thetailwindcss
CLI to compress them as well.I did not test this especially with
administrate
, but have this working on multiple projects where we want to slowly migrate to tailwind.Thank you all for your solutions to this, it’s been a headache! You solution @sedubois worked for me, thank you for sharing it. I just dropped
Rails.application.config.assets.css_compressor = nil
inconfig/initializers/assets.rb
and it worked.Actually, it looks like we managed to continue to use administrate, even with its dependency on the old sassc-rails, while the rest of our app changes to cssbundling-rails with Dart Sass (for our legacy views) and Tailwind (for new views). The key for us was to ensure
config.assets.css_compressor
was set tonil
for all Rails environments. Without this we encountered errors such asActionView::Template::Error: Error: Function rgb is missing argument $green
and I think also errors of the typeActionView::Template::Error: Asset X was not declared to be precompiled in production
. So far we haven’t needed to use one of the administrate forks suggested in this PR. Also see https://github.com/rails/cssbundling-rails/pull/129.The solution is pretty simple: we need to get rid of all JS/CSS dependencies and just mention how to add them in the README.
We must let developers choose the way they handle their assets, whether it’s using sassc, webpack or importmap.
Maybe we can add some generator
rails g administrate js:importmap
or something like that.Unfortunately, this may not be simple at all. Before Rails 7, there were two main ways of handling assets: Webpacker and Sprockets. We have tried to make Administrate work with both, but it’s difficult work and complex to reproduce issues.
Now Rails 7 has arrived with yet another way to do things. We’ll have to spend the time to make it work there too, and we would rather that Administrate kept working with previous versions of Rails (at the moment we support Rails 5+).
I haven’t used Rails 7 yet and I haven’t really read much about how the new way to work with assets is. I will have to eventually, but right now I’m a bit short of time so I don’t know when I’ll get to sit down and figure this out 😕
Fortunately, it doesn’t need to be us maintainers who do this work. One of you may be able to volunteer and offer a first stab at the solution. It doesn’t need to be a complete PR: an initial prototype could help communicate what exactly needs to happen, and to start testing if there are issues with back compatibility.
Any takers? 😃
Thank you all for your solutions to this. Your solution @kaka-ruto @sedubois Thank You. I just dropped Rails.application.config.assets.css_compressor = nil in config/initializers/assets.rb and it worked.
I would love it if there was official support for this. Is there anyway we can get this merged (maybe as a major version bump)?
I also tried various forks and solutions mentioned on this issue page. Nothing worked. I created a fork myself https://github.com/oroth8/administrate and it works perfectly with my rails 7 tailwind configured app.
@pablobm Here is my PR https://github.com/thoughtbot/administrate/pull/2116 I hope you like that solution.
Neither of the forks above worked for me (because I think administrate has pushed new commits after those forks were made). So I created a new up-to-date fork here: https://github.com/materialsnow/administrate
You can run
rails assets:precompile
locally in the app that is leveraging Administrate to make sure that step will work during your build. Just fix any errors (like adding the assets to manifest.js) and you should be good to go.It works for me as of this posting. I’m using Rails 7.0.4. Best of luck!
i just updated the branch, now you dont need to generate the assets in your project
@dvruette
This is a completely valid fix - but it will break if @n-studio deletes that particular branch in the future. And, it’s a development branch - not
main
- so it’s not reasonable to expect it to stick around. So, please fork the code to your own Github if you want to follow this approach! (and replacegithub: "n-studio/administrate"
with your own fork)@n-studio - I would consider it. If you create a PR so that I can see what it looks like, it can help me understand.
@pablobm I have a fork compatible with Rails 7, I’ll try to make it retrocompatible and submit a PR this weekend. Are you ok with the idea of adding generators to add assets in the Rails app? This would be a breaking change but the upgrade would be easy and straightforward.