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
- Add error handling to swc.config.js for missing shakapacker
- Add Prerequisites section documenting Shakapacker 9.0+ requirement
- Expand Troubleshooting section with additional common issues:
- Build fails with missing @swc/core
- Fast Refresh not working
- Syntax errors not being caught
- TypeScript files not transpiling
- Update config examples in documentation to include error handling
- Add eslint-disable for global-require (necessary for error handling)
These improvements make the migration guide more robust and help users
debug common SWC configuration issues.
Copy file name to clipboardExpand all lines: docs/swc-migration.md
+56-1Lines changed: 56 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,14 @@ This document describes the migration from Babel to SWC for JavaScript/TypeScrip
8
8
9
9
SWC (Speedy Web Compiler) is a Rust-based JavaScript/TypeScript compiler that is approximately 20x faster than Babel. Shakapacker 9.0+ uses SWC as the default transpiler.
10
10
11
+
## Prerequisites
12
+
13
+
-**Shakapacker 9.0+** - SWC support requires Shakapacker version 9.0 or higher
14
+
-**Node.js 18+** - Recommended for best compatibility
15
+
-**Yarn or npm** - For package management
16
+
17
+
This guide assumes you're already using Shakapacker 9.0+. If you need to upgrade from an earlier version, see the [Shakapacker upgrade guide](https://github.com/shakacode/shakapacker/blob/main/docs/v8_to_v9_upgrade.md).
18
+
11
19
## Migration Steps
12
20
13
21
**Note**: This migration has been successfully implemented in the React on Rails standard dummy app (`spec/dummy`). The Pro dummy app (`react_on_rails_pro/spec/dummy`) continues using Babel for RSC stability.
@@ -32,7 +40,14 @@ default: &default # Using SWC for faster JavaScript transpilation (20x faster th
32
40
Create `config/swc.config.js` in your Rails application root with the following content:
33
41
34
42
```javascript
35
-
const { env } = require('shakapacker');
43
+
let env;
44
+
try {
45
+
({ env } = require('shakapacker'));
46
+
} catch (error) {
47
+
console.error('Failed to load shakapacker:', error.message);
48
+
console.error('Make sure shakapacker is installed: yarn add shakapacker');
49
+
process.exit(1);
50
+
}
36
51
37
52
const customConfig = {
38
53
options: {
@@ -182,6 +197,46 @@ jsc: {
182
197
183
198
**Solution**: Already configured with `keepClassNames: true` in our SWC config.
184
199
200
+
### Issue: Build Fails with "Cannot find module '@swc/core'"
201
+
202
+
**Solution**: Clear node_modules and reinstall:
203
+
204
+
```bash
205
+
rm -rf node_modules yarn.lock
206
+
yarn install
207
+
```
208
+
209
+
### Issue: Fast Refresh Not Working
210
+
211
+
**Solution**: Ensure webpack-dev-server is running and check that:
212
+
213
+
- `env.runningWebpackDevServer`is true in development
214
+
- No syntax errors in components
215
+
- Components follow Fast Refresh rules (no anonymous exports, must export React components)
216
+
217
+
### Issue: Syntax Errors Not Being Caught
218
+
219
+
**Solution**: SWC parser is more permissive than Babel. Add TypeScript or stricter ESLint configuration for better error catching:
0 commit comments