Skip to content

Commit 82b1a1a

Browse files
justin808claude
andcommitted
Clarify js-routes as optional dependency in documentation
## Problem Documentation gave the impression that js-routes was a core react_on_rails requirement, when it's actually an optional integration used only in specific scenarios. ## Changes Made ### troubleshooting-build-errors.md - Added clear note that missing routes error only occurs with js-routes gem - Explained when js-routes IS and ISN'T needed - Provided alternative solution: remove ProvidePlugin if not using js-routes - Distinguished modern SPA patterns from Rails-heavy integration patterns ### coding-agents-guide.md - Added "(if using js-routes gem)" qualifier to all js:export commands - Updated auto-fix functions to clarify js-routes context - Modified diagnostic scripts to indicate js-routes dependency ### Environment dependencies - Clarified that rails js:export is only needed for js-routes gem ## Result - Documentation now accurately reflects js-routes as optional - Developers won't be confused into thinking it's required for react_on_rails - Clear guidance on when to use js-routes vs modern alternatives - Better separation of concerns between react_on_rails core and optional integrations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 015ea0c commit 82b1a1a

File tree

2 files changed

+40
-35
lines changed

2 files changed

+40
-35
lines changed

docs/contributor-info/coding-agents-guide.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ rails generate react_on_rails:install
9292
bundle install
9393
npm install
9494

95-
# 5. Generate routes
95+
# 5. Generate routes (if using js-routes gem)
9696
bundle exec rails js:export
9797

9898
# 6. Test
@@ -112,7 +112,7 @@ sed -i 's/"react-on-rails": "^14\./"react-on-rails": "^16./' package.json
112112
bundle update react_on_rails
113113
npm install
114114

115-
# 3. Generate routes (critical)
115+
# 3. Generate routes (if using js-routes gem)
116116
bundle exec rails js:export
117117

118118
# 4. Test build
@@ -175,10 +175,10 @@ detect_error_type() {
175175
### Auto-fix Strategies
176176

177177
```bash
178-
# Auto-fix missing routes
178+
# Auto-fix missing routes (only if using js-routes gem)
179179
fix_missing_routes() {
180180
if [ ! -f "app/javascript/utils/routes.js" ]; then
181-
echo "🔧 Generating missing routes file..."
181+
echo "🔧 Generating missing routes file (js-routes gem)..."
182182
bundle exec rails js:export
183183
return $?
184184
fi
@@ -203,7 +203,7 @@ fix_webpack_cache() {
203203

204204
### Common Error Scenarios
205205

206-
#### 1. Missing Routes File
206+
#### 1. Missing Routes File (js-routes gem)
207207

208208
**Detection:**
209209
```regex
@@ -288,9 +288,9 @@ else
288288
echo "❌ Build failed"
289289
echo "Running auto-fixes..."
290290

291-
# Auto-fix missing routes
291+
# Auto-fix missing routes (only if using js-routes gem)
292292
if [ ! -f "app/javascript/utils/routes.js" ]; then
293-
echo "🔧 Generating routes..."
293+
echo "🔧 Generating routes (js-routes gem)..."
294294
bundle exec rails js:export
295295
fi
296296

docs/javascript/troubleshooting-build-errors.md

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ This guide covers common webpack build errors encountered when using react_on_ra
1010
- [Shakapacker Compatibility Issues](#shakapacker-compatibility-issues)
1111
- [For Coding Agents](#for-coding-agents)
1212

13-
## Missing Routes File Error
13+
## Missing Routes File Error (js-routes gem)
14+
15+
**Note:** This error only occurs if you're using the optional `js-routes` gem to access Rails routes in JavaScript.
1416

1517
### Error Message
1618
```
@@ -20,9 +22,25 @@ TypeError: Cannot read properties of undefined (reading 'module')
2022
```
2123

2224
### Root Cause
23-
This error typically occurs when webpack's `ProvidePlugin` cannot resolve a module reference. A common case is when the Rails routes file hasn't been generated for JavaScript consumption.
24-
25-
### Solution
25+
This error occurs when:
26+
1. Your webpack config references Rails routes via ProvidePlugin
27+
2. The `js-routes` gem hasn't generated the JavaScript routes file
28+
3. You're using `js-routes` integration but missing the generated file
29+
30+
### When You Need js-routes
31+
`js-routes` is **optional** and typically used when:
32+
- Rails-heavy apps with React components that need to navigate to Rails routes
33+
- Server-side rendered apps mixing Rails and React routing
34+
- Legacy Rails apps migrating ERB views to React
35+
- Apps using Rails routing patterns for RESTful APIs
36+
37+
### When You DON'T Need js-routes
38+
Most modern React apps use:
39+
- Client-side routing (React Router) instead of Rails routes
40+
- Hardcoded API endpoints or environment variables
41+
- SPA (Single Page App) architecture with API-only Rails backend
42+
43+
### Solution (if using js-routes)
2644
1. **Generate JavaScript routes file:**
2745
```bash
2846
bundle exec rails js:export
@@ -33,34 +51,21 @@ This error typically occurs when webpack's `ProvidePlugin` cannot resolve a modu
3351
ls app/javascript/utils/routes.js
3452
```
3553

36-
3. **Check webpack configuration:**
37-
Ensure your webpack config has the correct ProvidePlugin setup:
54+
3. **Check webpack configuration includes ProvidePlugin:**
3855
```javascript
3956
new webpack.ProvidePlugin({
4057
Routes: "$app/utils/routes"
4158
})
4259
```
4360

44-
4. **Verify alias configuration:**
45-
```javascript
46-
resolve: {
47-
alias: {
48-
$app: path.join(rootPath, "app/javascript"),
49-
}
50-
}
51-
```
52-
53-
### Prevention
54-
- Always run `rails js:export` after initial setup
55-
- Include this step in your development setup documentation
56-
- Consider adding it to your `package.json` setup script:
57-
```json
58-
{
59-
"scripts": {
60-
"setup": "bundle exec rails js:export && npm install"
61-
}
62-
}
63-
```
61+
### Alternative Solution (if NOT using js-routes)
62+
Remove the Routes ProvidePlugin from your webpack configuration:
63+
```javascript
64+
// Remove this line if you don't use js-routes
65+
new webpack.ProvidePlugin({
66+
Routes: "$app/utils/routes" // ← Remove this
67+
})
68+
```
6469

6570
## ProvidePlugin Module Resolution Errors
6671

@@ -104,9 +109,9 @@ This error typically occurs when webpack's `ProvidePlugin` cannot resolve a modu
104109
## Environment Setup Dependencies
105110

106111
### Rails Environment Required
107-
Some react_on_rails operations require a working Rails environment:
112+
Some operations require a working Rails environment:
108113

109-
- `rails js:export` (generates routes)
114+
- `rails js:export` (generates routes - **only needed if using js-routes gem**)
110115
- Asset precompilation
111116
- Server-side rendering
112117

0 commit comments

Comments
 (0)