Skip to content

Commit cbe2d51

Browse files
committed
Clarify Shakapacker package manager preflights
1 parent ec65794 commit cbe2d51

4 files changed

Lines changed: 22 additions & 13 deletions

File tree

docs/oss/getting-started/installation-into-an-existing-rails-app.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Use this path when you already have a Rails application and want React on Rails
77
- Rails 7+ is recommended. Rails 5.2+ can work, but Webpacker-era apps usually need an incremental upgrade first.
88
- If your app still uses `webpacker`, expect this to be a two-step migration: move to `shakapacker`, then install React on Rails.
99
- If `bundle install` is already failing on older native gems such as `pg`, `nio4r`, `mysql2`, or `msgpack`, fix that baseline first. React on Rails installation cannot get past a broken app bundle.
10-
- If your repo has a `yarn.lock` but no `"packageManager"` field in `package.json`, add one before introducing Shakapacker 9. Example: `"packageManager": "yarn@1.22.22"`.
10+
- If your repo has a `yarn.lock` but no `"packageManager"` field in `package.json`, add one before introducing Shakapacker 9. Example for Yarn Classic: `npm pkg set packageManager="yarn@1.22.22"` (or add the field manually). Use the version that matches your project's Yarn installation.
1111
- The install generator boots your app. Make sure `config/database.yml` exists and any required env vars for initializers are set before running `rails generate`.
1212
- If your app is Rails 5 API-only, first [convert it to a standard Rails app](../migrating/convert-rails-5-api-only-app.md).
1313
- Commit or stash your current work if you want the generated diff to be easier to review. The generator updates files like `bin/dev`, `config/shakapacker.yml`, routes, initializers, and sample views/controllers.

docs/oss/migrating/migrating-from-react-rails.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Before swapping gems, check these first:
1212
2. **Bundler age**: some older `react-rails` apps still carry Bundler 1.x lockfiles. Those can fail on modern Ruby before you even reach the migration work.
1313
3. **Native gem age**: older lockfiles often pin `nio4r`, `pg`, or `mysql2` versions that fail to compile on current macOS and Ruby before the migration even starts.
1414
4. **App boot readiness**: the React on Rails install generator boots the full Rails app. Make sure `config/database.yml` exists and required env vars for initializers are set.
15-
5. **Package manager metadata**: if the repo has a `yarn.lock` but no `"packageManager"` field in `package.json`, add one before introducing Shakapacker 9. Example: `"packageManager": "yarn@1.22.22"`.
15+
5. **Package manager metadata**: if the repo has a `yarn.lock` but no `"packageManager"` field in `package.json`, add one before introducing Shakapacker 9. Example for Yarn Classic: `npm pkg set packageManager="yarn@1.22.22"` (or add the field manually). Use the version that matches your project's Yarn installation.
1616
6. **Rails age**: current `react_on_rails` requires Rails 5.2+. Rails 5.1 / Webpacker 3 apps are usually a staged migration, not a one-command migration.
1717

1818
If you are already on `shakapacker` 7+ and React 18+, the migration is mostly about helper syntax, component registration, and generated defaults.
@@ -29,7 +29,7 @@ If the first failure is a native gem compile error, solve that before swapping t
2929
1. Update Deps
3030
1. Replace `react-rails` in `Gemfile` with `react_on_rails` and make sure `shakapacker` is present.
3131
2. Remove `react_ujs` from `package.json`.
32-
3. If the repo uses Yarn and `package.json` does not already declare it, add `"packageManager": "yarn@1.22.22"` before booting the app with Shakapacker 9.
32+
3. If the repo uses Yarn and `package.json` does not already declare it, add the package manager field before booting the app with Shakapacker 9: `npm pkg set packageManager="yarn@1.22.22"` (or add it manually to `package.json`). The example is for Yarn Classic; use the version that matches your project.
3333
4. Run `bundle install` and your package manager's install command.
3434
5. Commit changes.
3535

docs/oss/migrating/migrating-from-vite-rails.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Before you start, make sure the current app still installs cleanly on the Ruby a
1919

2020
- If `bundle install` fails on older native gems such as `pg`, `nio4r`, `mysql2`, or `msgpack`, refresh those gems or use the Ruby version already pinned by the app before introducing React on Rails.
2121
- If the app has an older Bundler-era lockfile, refresh that lockfile first.
22-
- If the repo uses Yarn and has a `yarn.lock` but no `"packageManager"` field in `package.json`, add one before introducing Shakapacker 9. Example: `"packageManager": "yarn@1.22.22"`.
22+
- If the repo uses Yarn and has a `yarn.lock` but no `"packageManager"` field in `package.json`, add one before introducing Shakapacker 9. Example for Yarn Classic: `npm pkg set packageManager="yarn@1.22.22"` (or add the field manually). Use the version that matches your project's Yarn installation.
2323
- The React on Rails install generator boots the full app. Make sure `config/database.yml` exists and any required env vars for initializers are set before you run it.
2424
- Commit or stash your current work so the generator diff is easier to review.
2525

@@ -45,18 +45,27 @@ For anything beyond a tiny app, prefer a route-by-route cutover instead of a big
4545
```bash
4646
bundle add shakapacker --strict
4747
bundle add react_on_rails --strict
48-
bundle exec rails generate react_on_rails:install
4948
```
5049

51-
If you use Yarn and `package.json` does not already declare it, set the package manager before running the generator:
50+
## 2. Declare the package manager if needed
51+
52+
If you use Yarn and `package.json` does not already declare it, set the package manager before running the generator. This only updates `package.json`; it does not install or switch Yarn for you.
5253

5354
```bash
5455
npm pkg set packageManager="yarn@1.22.22"
5556
```
5657

58+
If you prefer, add the same field manually in `package.json`. The example above is for Yarn Classic; use the version that matches your project.
59+
60+
## 3. Run the generator
61+
62+
```bash
63+
bundle exec rails generate react_on_rails:install
64+
```
65+
5766
The generator adds the React on Rails initializer, `bin/dev`, Shakapacker config, example routes, and the server bundle entrypoint.
5867

59-
## 2. Replace Vite layout tags
68+
## 4. Replace Vite layout tags
6069

6170
A typical Vite layout looks like this:
6271

@@ -76,7 +85,7 @@ React on Rails + Shakapacker layouts use pack tags instead:
7685

7786
If you use React on Rails auto-bundling, keep those empty pack-tag placeholders in the layout and let React on Rails load component-specific bundles per page.
7887

79-
## 3. Move frontend code into the React on Rails structure
88+
## 5. Move frontend code into the React on Rails structure
8089

8190
A common Vite layout is:
8291

@@ -101,7 +110,7 @@ For auto-bundling, move page-level components into a `ror_components` directory,
101110
app/javascript/src/Hero/ror_components/Hero.client.jsx
102111
```
103112

104-
## 4. Replace client bootstraps with Rails view rendering
113+
## 6. Replace client bootstraps with Rails view rendering
105114

106115
Vite apps often mount React manually from an entrypoint:
107116

@@ -117,7 +126,7 @@ With React on Rails, render the component from the Rails view instead:
117126

118127
This is the key mental model shift: Rails decides where the component mounts, and React on Rails handles registration and hydration.
119128

120-
## 5. Replace Vite-specific asset and env usage
129+
## 7. Replace Vite-specific asset and env usage
121130

122131
### `vite_asset_path`
123132

@@ -135,7 +144,7 @@ Vite-specific `import.meta.env` usage needs to be replaced. In a React on Rails
135144
- Rails-passed props
136145
- `railsContext` for request-aware values
137146

138-
## 6. Replace the development workflow
147+
## 8. Replace the development workflow
139148

140149
Vite apps usually have a dev command like:
141150

@@ -153,7 +162,7 @@ bin/rails db:prepare
153162
bin/dev
154163
```
155164

156-
## 7. Remove Vite once parity is confirmed
165+
## 9. Remove Vite once parity is confirmed
157166

158167
After the new React on Rails entrypoints are working, remove:
159168

docs/oss/upgrading/upgrading-react-on-rails.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Before changing versions, check these first:
3131
4. **Asset stack**: if the app still uses `webpacker`, upgrade to `shakapacker` first.
3232
5. **Native gem age**: older `pg`, `nio4r`, `mysql2`, or `msgpack` versions can fail on current Ruby or macOS before the React on Rails upgrade even begins.
3333
6. **App boot readiness**: the install generator boots the full Rails app. Make sure `config/database.yml` exists and required env vars for initializers are set.
34-
7. **Package manager metadata**: if the repo has a `yarn.lock` but no `"packageManager"` field in `package.json`, add one before introducing Shakapacker 9. Example: `"packageManager": "yarn@1.22.22"`.
34+
7. **Package manager metadata**: if the repo has a `yarn.lock` but no `"packageManager"` field in `package.json`, add one before introducing Shakapacker 9. Example for Yarn Classic: `npm pkg set packageManager="yarn@1.22.22"` (or add the field manually). Use the version that matches your project's Yarn installation.
3535
8. **Version pinning**: use exact gem and npm package versions for React on Rails-related packages. Avoid `^`, `~`, or `*`.
3636

3737
If your app is both Ruby/Bundler-old and Webpacker-old, do those upgrades first. Trying to jump directly from a Rails 5 / Webpacker 3 / Bundler 1 stack to current React on Rails is usually more than one migration.

0 commit comments

Comments
 (0)