Skip to content

Commit 1d2333a

Browse files
authored
Merge pull request #530 from rails/flavorjones/better-debugging
Improve the state of debugging when things go wrong
2 parents abea8c0 + fd25059 commit 1d2333a

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

Diff for: README.md

+34-1
Original file line numberDiff line numberDiff line change
@@ -403,30 +403,63 @@ If you need to use a custom input or output file, you can run `bundle exec tailw
403403
404404
## Troubleshooting
405405
406-
Some common problems experienced by users ...
406+
When having trouble with `tailwindcss:build` or `tailwindcss:watch`, the first thing you should do is collect some diagnostic information by setting the "verbose" flag, which will emit:
407+
408+
1. the command being run (so you can try running `tailwindcss` yourself without the gem's help)
409+
2. additional debugging output from `tailwindcss` by setting the env var `DEBUG=1`
410+
411+
Here's what that looks like:
412+
413+
``` sh
414+
$ bin/rails tailwindcss:build[verbose]
415+
416+
Running: /path/to/tailwindcss-ruby-4.0.17-x86_64-linux-gnu/exe/x86_64-linux-gnu/tailwindcss -i /home/flavorjones/code/oss/tailwindcss-rails/My Workspace/test-install/app/assets/tailwind/application.css -o /home/flavorjones/code/oss/tailwindcss-rails/My Workspace/test-install/app/assets/builds/tailwind.css --minify
417+
≈ tailwindcss v4.0.17
418+
419+
Done in 37ms
420+
421+
[38.22ms] [@tailwindcss/cli] (initial build)
422+
[11.90ms] ↳ Setup compiler
423+
[ 6.52ms] ↳ Scan for candidates
424+
[10.39ms] ↳ Build CSS
425+
[ 1.69ms] ↳ Optimize CSS
426+
[ 5.80ms] ↳ Write output
427+
```
428+
429+
### The `watch` command is hanging
430+
431+
There is a [known issue](https://github.com/tailwindlabs/tailwindcss/issues/17246#issuecomment-2753067488) running `tailwindcss -w` (that's the CLI in watch mode) when the utility `watchman` is also installed.
432+
433+
Please try uninstalling `watchman` and try running the watch task again.
434+
407435
408436
### Lost keystrokes or hanging when using terminal-based debugging tools (e.g. IRB, Pry, `ruby/debug`...etc.) with the Puma plugin
409437
410438
We've addressed the issue and you can avoid the problem by upgrading `tailwindcss-rails` to [v2.4.1](https://github.com/rails/tailwindcss-rails/releases/tag/v2.4.1) or later versions.
411439
440+
412441
### Running in a docker container exits prematurely
413442
414443
If you are running `rails tailwindcss:watch` as a process in a Docker container, set `tty: true` in `docker-compose.yml` for the appropriate container to keep the watch process running.
415444
416445
If you are running `rails tailwindcss:watch` in a docker container without a tty, pass the `always` argument to the task to instruct tailwindcss to keep the watcher alive even when `stdin` is closed: `rails tailwindcss:watch[always]`. If you use `bin/dev` then you should modify your `Procfile.dev`.
417446
447+
418448
### Conflict with sassc-rails
419449
420450
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.
421451
452+
422453
### Class names must be spelled out
423454
424455
For Tailwind to work, your class names need to be spelled out. If you need to make sure Tailwind generates class names that don't exist in your content files or that are programmatically composed, use the [safelist option](https://tailwindcss.com/docs/content-configuration#safelisting-classes).
425456
457+
426458
### `ERROR: Cannot find the tailwindcss executable` for supported platform
427459
428460
See https://github.com/flavorjones/tailwindcss-ruby for help.
429461
462+
430463
### Using asset-pipeline assets
431464
432465
In Rails, you want to use [assets from the asset pipeline to get fingerprinting](https://guides.rubyonrails.org/asset_pipeline.html#fingerprinting-versioning-with-digest-based-urls). However, Tailwind isn't aware of those assets.

Diff for: lib/tailwindcss/commands.rb

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ def watch_command(always: false, poll: false, **kwargs)
2929
end
3030
end
3131

32+
def command_env(verbose:)
33+
{}.tap do |env|
34+
env["DEBUG"] = "1" if verbose
35+
end
36+
end
37+
3238
def rails_css_compressor?
3339
defined?(Rails) && Rails&.application&.config&.assets&.css_compressor.present?
3440
end

Diff for: lib/tasks/build.rake

+12-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@ namespace :tailwindcss do
22
desc "Build your Tailwind CSS"
33
task build: :environment do |_, args|
44
debug = args.extras.include?("debug")
5+
verbose = args.extras.include?("verbose")
6+
57
command = Tailwindcss::Commands.compile_command(debug: debug)
6-
puts command.inspect if args.extras.include?("verbose")
7-
system(*command, exception: true)
8+
env = Tailwindcss::Commands.command_env(verbose: verbose)
9+
puts "Running: #{Shellwords.join(command)}" if verbose
10+
11+
system(env, *command, exception: true)
812
end
913

1014
desc "Watch and build your Tailwind CSS on file changes"
1115
task watch: :environment do |_, args|
1216
debug = args.extras.include?("debug")
1317
poll = args.extras.include?("poll")
1418
always = args.extras.include?("always")
19+
verbose = args.extras.include?("verbose")
20+
1521
command = Tailwindcss::Commands.watch_command(always: always, debug: debug, poll: poll)
16-
puts command.inspect if args.extras.include?("verbose")
17-
system(*command)
22+
env = Tailwindcss::Commands.command_env(verbose: verbose)
23+
puts "Running: #{Shellwords.join(command)}" if verbose
24+
25+
system(env, *command)
1826
rescue Interrupt
1927
puts "Received interrupt, exiting tailwindcss:watch" if args.extras.include?("verbose")
2028
end

0 commit comments

Comments
 (0)