create-react-on-rails-app
The fastest way to start a new React on Rails project. One command creates a fully configured Rails + React application with TypeScript, server-side rendering, and hot module replacement.
Quick Start
npx create-react-on-rails-app my-app
cd my-app
bin/rails db:prepare
bin/dev
Visit http://localhost:3000/hello_world to see your React component.
This creates a TypeScript app by default. For JavaScript, use --template javascript.
For React Server Components (RSC), add --rsc and visit /hello_server after setup.
--rsc requires react_on_rails_pro to be installable in your environment
(Pro setup docs).
RSC supports both JavaScript (.jsx) and TypeScript (.tsx) templates.
Options
# JavaScript instead of TypeScript
npx create-react-on-rails-app my-app --template javascript
# Use Rspack for ~20x faster builds
npx create-react-on-rails-app my-app --rspack
# Generate React Server Components setup (includes react_on_rails_pro)
npx create-react-on-rails-app my-app --rsc
# Specify package manager
npx create-react-on-rails-app my-app --package-manager pnpm
# Combine options
npx create-react-on-rails-app my-app --rspack --package-manager pnpm
# Combine RSC with Rspack
npx create-react-on-rails-app my-app --rspack --rsc
All Options
| Option | Description | Default |
|---|---|---|
-t, --template <type> | javascript or typescript | typescript |
--rspack | Use Rspack instead of Webpack (~20x faster) | false |
--rsc | Enable React Server Components (requires react_on_rails_pro) | false |
-p, --package-manager <pm> | npm or pnpm | auto-detected |
What It Does
The CLI runs these steps automatically:
- Creates a Rails app (
rails newwith PostgreSQL, no default JS) - Adds required gems (
bundle add react_on_rails, plusreact_on_rails_profor--rsc) - Runs the generator (
rails generate react_on_rails:installwith your selected flags)
After completion, you get:
- A Rails 7+ app with PostgreSQL
- Shakapacker configured with Webpack (or Rspack) and HMR
- A working HelloWorld React component (TypeScript by default)
- Optional RSC setup (
--rsc) with HelloServer route and Pro Node renderer wiring - Server-side rendering ready
- Development scripts (
bin/devwith hot reloading)
Prerequisites
The CLI checks for these before starting:
- Node.js 18+
- Ruby 3.0+
- Rails 7.0+ (
gem install rails) - npm or pnpm
- PostgreSQL running locally (needed at
bin/rails db:prepare, not validated by the CLI)
If any of the first four are missing, you'll get a clear error message with installation instructions.
Adding to an Existing Rails App
If you already have a Rails app, use the generator directly instead:
bundle add react_on_rails --strict
rails generate react_on_rails:install --typescript # TypeScript (recommended)
rails generate react_on_rails:install # JavaScript
See Installation into an Existing Rails App for details.
What's Next?
Now that you have React on Rails running, here are ways to level up:
- Add server-side rendering — SSR guide
- See the feature comparison — OSS vs Pro
- Upgrade to Pro for React Server Components, streaming SSR, and 10-100x faster SSR — 3-step upgrade guide
- Explore the full docs — Documentation index