You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix critical installation order in AI agent instructions
🚨 BREAKING: Fixed installation sequence that was causing errors
**Root Cause Found:**
- React on Rails generator requires package.json to exist
- Rails 8 with --skip-javascript doesn't create package.json
- Previous instructions tried React on Rails first → package.json error
**Fix Applied:**
1. ✅ Always install Shakapacker FIRST (creates package.json)
2. ✅ Then install React on Rails (can add JS dependencies)
**Updated All 3 Scenarios:**
- New Rails App: Shakapacker → React on Rails
- Existing Rails App: Shakapacker → React on Rails
- Vite Migration: Remove Vite → Shakapacker → React on Rails
**Validated:**
- Created test app following new instructions → SUCCESS
- React component renders, HMR works, no errors
- Updated to current gem versions (15.0, 8.3)
This fix prevents the "package.json not found" error that breaks setup.
# Or use specific versions from these commands in your Gemfile:
13
13
# Latest stable versions as of Jan 2025:
14
-
# react_on_rails ~> 14.2
15
-
# shakapacker ~> 8.1
14
+
# react_on_rails ~> 15.0
15
+
# shakapacker ~> 8.3
16
16
```
17
17
18
18
**⚠️ Version Flexibility:** These instructions use `~> X.Y` which allows patch updates. Always check for latest versions before starting a new project.
19
19
20
+
## 🚨 **CRITICAL: Installation Order Matters**
21
+
22
+
**ALWAYS install Shakapacker FIRST, then React on Rails. Here's why:**
23
+
24
+
1.**React on Rails generator requires `package.json`** to add JavaScript dependencies
25
+
2.**Rails with `--skip-javascript` doesn't create `package.json`**
26
+
3.**Shakapacker creates `package.json`** and JavaScript tooling foundation
27
+
4.**Wrong order = "package.json not found" error**
28
+
29
+
**✅ Correct Order:**
30
+
```
31
+
Shakapacker → package.json created → React on Rails → success
32
+
```
33
+
34
+
**❌ Wrong Order:**
35
+
```
36
+
React on Rails → no package.json → ERROR: package.json not found
37
+
```
38
+
20
39
---
21
40
22
41
## 🆕 Scenario 1: New Rails App with React on Rails
23
42
24
43
```bash
25
-
# Create new Rails app with essential gems
44
+
# Create new Rails app
26
45
rails new myapp --skip-javascript --database=postgresql
27
46
cd myapp
28
47
29
-
# Add React on Rails to Gemfile (latest versions)
30
-
echo'gem "react_on_rails", "~> 14.2"'>> Gemfile
31
-
echo'gem "shakapacker", "~> 8.1"'>> Gemfile
48
+
# STEP 1: Add Shakapacker first (creates package.json)
49
+
echo'gem "shakapacker", "~> 8.3"'>> Gemfile
32
50
bundle install
51
+
bundle exec rails shakapacker:install
33
52
34
-
# Install React on Rails with Node dependencies
53
+
# STEP 2: Add React on Rails (requires package.json to exist)
54
+
echo'gem "react_on_rails", "~> 15.0"'>> Gemfile
55
+
bundle install
35
56
rails generate react_on_rails:install
36
-
yarn install
37
57
38
58
# Start development servers
39
59
bin/dev
@@ -54,23 +74,20 @@ bin/dev
54
74
# Navigate to existing Rails app root
55
75
cd /path/to/existing/app
56
76
57
-
# Add gems to Gemfile (before final 'end')
58
-
cat >> Gemfile << 'EOF'
77
+
# STEP 1: Add Shakapacker first (creates package.json if missing)
78
+
echo'gem "shakapacker", "~> 8.3"'>> Gemfile
79
+
bundle install
59
80
60
-
# React on Rails
61
-
gem "react_on_rails", "~> 14.2"
62
-
gem "shakapacker", "~> 8.1"
63
-
EOF
81
+
#Check if package.json exists, create if missing
82
+
if [ !-f"package.json" ];then
83
+
bundle exec rails shakapacker:install
84
+
fi
64
85
65
-
# Install gems
86
+
# STEP 2: Add React on Rails (requires package.json to exist)
87
+
echo'gem "react_on_rails", "~> 15.0"'>> Gemfile
66
88
bundle install
67
-
68
-
# Install React on Rails (will not overwrite existing files)
0 commit comments