In a Rails 8.1 app with jsbundling-rails and dartsass-rails, what do bin/dev and Procfile.dev run, and what goes wrong if you start only bin/rails server?
answer
- foreman start -f Procfile.dev
- web, js and css processes
- watchers rewrite app/assets/builds
- missing build: MissingAssetError or no link
- RUBY_DEBUG_OPEN for breakpoints
basics
~10 sbin/dev runs foreman on Procfile.dev: the Rails server plus yarn build --watch and bin/rails dartsass:watch. With only bin/rails server nothing rebuilds app/assets/builds, so edits never appear and a fresh clone has no built files.
solid answer
~40 sThe bundling installers copy a `bin/dev` that installs foreman if missing, defaults `PORT` to 3000 and runs `foreman start -f Procfile.dev`. Each installer writes or appends one line to `Procfile.dev`: `web: env RUBY_DEBUG_OPEN=true bin/rails server`, `js: yarn build --watch` from jsbundling-rails, `css: bin/rails dartsass:watch` from dartsass-rails. The watchers rewrite `app/assets/builds` on every save and Propshaft serves the new files. Start only `bin/rails server` and nothing rebuilds: edits to TypeScript or Sass never show, and on a fresh clone the git-ignored builds are missing, so `javascript_include_tag "application"` raises `Propshaft::MissingAssetError`, while `stylesheet_link_tag :app` simply links no theme. `RUBY_DEBUG_OPEN=true` makes the debug gem open a remote port, because foreman's interleaved output makes an interactive `debugger` prompt impractical; attach with `rdbg --attach`.
code
yaml · 3 linesweb: env RUBY_DEBUG_OPEN=true bin/rails server
js: yarn build --watch
css: bin/rails dartsass:watchgo deeper
Recall that bin/dev starts the server and the build watchers from Procfile.dev, and that bin/rails server alone does not rebuild assets.
Explain which installer writes which Procfile.dev line, why builds go missing on a fresh clone, and the error-versus-silence difference between the two tags.
Diagnose stale or missing assets from foreman's output and app/assets/builds, and set up remote debugging behind foreman with RUBY_DEBUG_OPEN.
Decide how much development tooling a team standardises on: one bin/dev entry point versus per-developer setups, and the onboarding cost of each.
## Why one command starts several processes A bundler app has more than one long-running process in development: the Rails server, a JavaScript bundler in watch mode and usually a CSS compiler in watch mode. Rails' answer is a **Procfile** run by **foreman**, a process manager that starts every line as its own process and interleaves their output in one terminal. ## What the installers write Each bundling gem's installer copies the same `bin/dev` (with `force: true`, replacing the plain one) and creates or extends `Procfile.dev`: | Installer | Line it contributes | |---|---| | jsbundling-rails (esbuild, rollup, webpack) | `web: env RUBY_DEBUG_OPEN=true bin/rails server` and `js: yarn build --watch` | | jsbundling-rails (bun) | `web: ...` and `js: bun run build --watch` | | dartsass-rails | `css: bin/rails dartsass:watch` (plus a `web:` line if it creates the file) | | tailwindcss-rails | `css: bin/rails tailwindcss:watch` | | cssbundling-rails | `css: yarn build:css --watch` (or the Bun form) | The first installer to run creates the file; later ones append their line. `rails new -j esbuild -c sass` on a machine with Node therefore ends with `web`, `js` and `css` processes. The generated `bin/dev` itself is short: ```sh if gem list --no-installed --exact --silent foreman; then gem install foreman fi export PORT="${PORT:-3000}" exec foreman start -f Procfile.dev --env /dev/null "$@" ``` An app on import maps with no CSS gem keeps Rails' own `bin/dev`, which is just `exec "./bin/rails", "server", *ARGV`, because there is nothing to watch. ## What goes wrong with only bin/rails server The watchers are the only thing that writes `app/assets/builds` during development. Without them: 1. **Edits do not appear.** Propshaft serves whatever was last built, so a change to `app/javascript/leases.ts` or `app/assets/stylesheets/_theme.scss` has no effect. 2. **A fresh clone has no builds at all.** The folder is git-ignored except for `.keep`. Then: - `javascript_include_tag "application"` cannot resolve `application.js` and raises **`Propshaft::MissingAssetError`** while rendering the layout; - `stylesheet_link_tag :app` links only the `.css` files that exist, so the built theme is silently absent and the page renders unstyled with no error. 3. **Tests may still pass.** `bin/rails test` runs `test:prepare`, which the gems enhance with their build tasks, so the test suite builds assets even when the developer's server does not. ## Why RUBY_DEBUG_OPEN=true is on the web line foreman interleaves the output of every process in one terminal, which makes an interactive prompt from a `debugger` call impractical there. `RUBY_DEBUG_OPEN=true` tells the debug gem to open a remote debugging port instead; from another terminal, `rdbg --attach` connects to the paused process. ## Alternatives to foreman - Run each watcher yourself: `bin/rails server` in one terminal and `yarn build --watch` and `bin/rails dartsass:watch` in others. - For Tailwind only, tailwindcss-rails ships a Puma plugin: `plugin :tailwindcss if ENV.fetch("RAILS_ENV", "development") == "development"` in `config/puma.rb` makes `bin/rails server` start the Tailwind watcher itself. - Run the build once (`yarn build`, `bin/rails dartsass:build`) when you only need current files, for example before a quick demo. ## Habits that prevent confusion - Start the app with `bin/dev`, not `bin/rails server`, whenever `Procfile.dev` exists. - If styles look wrong, check `app/assets/builds` first: a missing or old file means a watcher is not running or has crashed (its errors appear in foreman's output, prefixed with the process name). - Keep extra development processes, such as a job worker, as additional `Procfile.dev` lines so `bin/dev` remains the single entry point. ## Passing options through bin/dev `bin/dev` ends with `exec foreman start -f Procfile.dev --env /dev/null "$@"`, so anything after `bin/dev` goes to foreman, not to Rails: 1. `PORT=4000 bin/dev` changes the base port, and the `web` process listens there. 2. `--env /dev/null` stops foreman from loading a `.env` file on its own, so environment variables come from your shell or the app's own configuration. 3. `bin/dev -m all=1,css=0` passes foreman's formation option, useful to leave the CSS watcher off while working only on TypeScript; `bin/dev web` starts just the one named process. Knowing that the script is a thin foreman wrapper is the key to debugging it: if a process will not start, run its `Procfile.dev` command by hand and read the error directly. When one process exits, foreman stops the others too, so a crashing CSS watcher takes the web server down with it — read the first error in the output, not the last.
- Why does bin/dev set PORT to 3000 when it is unset?foreman assigns ports to its processes from a base port, which is 5000 unless `PORT` is set. The generated script exports `PORT=${PORT:-3000}` before `foreman start`, so the Rails server keeps the familiar port 3000 unless you choose another.
- A Tailwind-only app wants no foreman. What does tailwindcss-rails offer?A Puma plugin. Adding `plugin :tailwindcss` (guarded to development) to `config/puma.rb` makes Puma fork `bin/rails tailwindcss:watch` alongside the server and stop it when Puma stops, so `bin/rails server` alone keeps `app/assets/builds/tailwind.css` current.
A restaurant kitchen during service: the waiter (the Rails server) only carries out what is on the pass. The cooks (the watchers) keep putting fresh plates there as orders change. Send the cooks home and the waiter keeps serving the last plates left on the pass — or nothing at all if the pass was empty when service started.
- bin/rails server rebuilds the TypeScript bundle on each request
- Procfile.dev is read by Kamal in production
- A missing built stylesheet always raises an error, so you would notice
- bin/dev is identical in every Rails 8.1 app, bundler or not
- RUBY_DEBUG_OPEN=true turns on verbose request logging