When working with Rails 8 and Tailwind CSS v4, many developers face issues like missing styles, 404 errors for Tailwind assets, or conflicts due to outdated setup commands. Below are the key reasons and the solutions.
Error message:
GET http://127.0.0.1:3000/assets/tailwindcss net::ERR_ABORTED 404 (Not Found)
This happens because in Rails 8, Tailwind files are placed in a new directory structure. If you are looking for styles in the old application.tailwind.css path, Rails cannot find them.
In your Rails layout (app/views/layouts/application.html.erb), you should include the compiled CSS like this:
<%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %>
Older versions used:
@tailwind base;
@tailwind components;
@tailwind utilities;
In Tailwind v4, you should replace these with:
@import "tailwindcss";
This avoids conflicts with the new Rails 8 asset pipeline (Propshaft).
Run the following commands in your project root:
bin/bundle add tailwindcss-rails
bin/rails tailwindcss:install
This generates the config, sets up the correct asset paths, and creates a Procfile.dev.
To make Tailwind compile on file changes, start the watcher with:
bin/rails tailwindcss:watch
Or run everything together (Rails + Tailwind watcher) using:
bin/dev
In config/puma.rb, add:
plugin :tailwindcss if ENV.fetch("RAILS_ENV", "development") == "development"
This way, just running rails server will also start the Tailwind watcher.
Ensure you have app/assets/tailwind/application.css with:
@import "tailwindcss";
Ensure application.html.erb includes:
<%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %>
Run bin/dev to start both Rails and Tailwind watchers.
This setup will fix the “Unable to install Tailwind CSS in Rails 8 App” issue and ensure your styles compile and load correctly.
Work with our skilled Ruby on Rails developers to accelerate your project and boost its performance.
Hire Ruby on Rails Developer