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
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>
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)
26
44
1.**Generate JavaScript routes file:**
27
45
```bash
28
46
bundle exec rails js:export
@@ -33,34 +51,21 @@ This error typically occurs when webpack's `ProvidePlugin` cannot resolve a modu
33
51
ls app/javascript/utils/routes.js
34
52
```
35
53
36
-
3.**Check webpack configuration:**
37
-
Ensure your webpack config has the correct ProvidePlugin setup:
54
+
3.**Check webpack configuration includes ProvidePlugin:**
38
55
```javascript
39
56
newwebpack.ProvidePlugin({
40
57
Routes:"$app/utils/routes"
41
58
})
42
59
```
43
60
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:
0 commit comments