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
Improve React on Rails documentation for v16 and coding agents
- **troubleshooting-build-errors.md**: Comprehensive guide for webpack/build issues
- Missing routes file error patterns and solutions
- ProvidePlugin module resolution troubleshooting
- Environment setup dependencies and workarounds
- Agent-friendly diagnostic scripts and auto-fixes
- **coding-agents-guide.md**: Structured workflows for AI coding agents
- Version compatibility matrix
- Installation and upgrade workflows with error detection
- Auto-fix strategies for common issues
- Emergency procedures and rollback guidance
- **upgrading-react-on-rails.md**:
- Removed js:export from upgrade steps (it's a setup issue, not upgrade-specific)
- Focused troubleshooting on actual upgrade-related issues
- Added reference to comprehensive build errors guide
- **getting-started.md**: Updated to use react_on_rails v16.0.0
- **home.md**: Added troubleshooting guide to navigation
- Separated setup/installation issues from upgrade-specific issues
- Provided agent-friendly automation and error detection
- Enhanced troubleshooting with actionable solutions
- Improved documentation discoverability
These improvements make react_on_rails documentation more comprehensive
and accessible for both human developers and AI coding agents.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
**Note:** This error only occurs if you're using the optional `js-routes` gem to access Rails routes in JavaScript.
13
+
## Missing Routes File Error
16
14
17
15
### Error Message
18
-
19
16
```
20
17
Cannot read properties of undefined (reading 'module')
21
18
TypeError: Cannot read properties of undefined (reading 'module')
22
19
at ProvidedDependencyTemplate.apply
23
20
```
24
21
25
22
### 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.
26
24
27
-
This error occurs when:
28
-
29
-
1. Your webpack config references Rails routes via ProvidePlugin
30
-
2. The `js-routes` gem hasn't generated the JavaScript routes file
31
-
3. You're using `js-routes` integration but missing the generated file
32
-
33
-
### When You Need js-routes
34
-
35
-
`js-routes` is **optional** and typically used when:
36
-
37
-
- Rails-heavy apps with React components that need to navigate to Rails routes
38
-
- Server-side rendered apps mixing Rails and React routing
39
-
- Legacy Rails apps migrating ERB views to React
40
-
- Apps using Rails routing patterns for RESTful APIs
41
-
42
-
### When You DON'T Need js-routes
43
-
44
-
Most modern React apps use:
45
-
46
-
- Client-side routing (React Router) instead of Rails routes
47
-
- Hardcoded API endpoints or environment variables
48
-
- SPA (Single Page App) architecture with API-only Rails backend
49
-
50
-
### Solution (if using js-routes)
51
-
25
+
### Solution
52
26
1.**Generate JavaScript routes file:**
53
-
54
27
```bash
55
28
bundle exec rails js:export
56
29
```
57
30
58
31
2.**Verify the routes file was created:**
59
-
60
32
```bash
61
33
ls app/javascript/utils/routes.js
62
34
```
63
35
64
-
3.**Check webpack configuration includes ProvidePlugin:**
36
+
3.**Check webpack configuration:**
37
+
Ensure your webpack config has the correct ProvidePlugin setup:
65
38
```javascript
66
39
newwebpack.ProvidePlugin({
67
-
Routes:'$app/utils/routes',
68
-
});
40
+
Routes:"$app/utils/routes"
41
+
})
69
42
```
70
43
71
-
### Alternative Solution (if NOT using js-routes)
72
-
73
-
Remove the Routes ProvidePlugin from your webpack configuration:
74
-
75
-
```javascript
76
-
// Remove this line if you don't use js-routes
77
-
newwebpack.ProvidePlugin({
78
-
Routes:'$app/utils/routes', // ← Remove this
79
-
});
80
-
```
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