Skip to content

Commit 57a49ad

Browse files
justin808claude
andcommitted
Fix React 19 webpack build failures: add swc-loader and configure target: node
This commit fixes CI build failures by: 1. **Add missing swc-loader dependencies** - Added @swc/core and swc-loader to spec/dummy package.json - Added @swc/core and swc-loader to Pro dummy and execjs-compatible-dummy - Shakapacker 9.3.0 requires these for SWC compilation 2. **Fix webpack server bundle configuration for React 19** - Set `target: 'node'` to properly handle Node.js built-in modules (crypto, async_hooks, stream) - Set `libraryTarget: 'commonjs2'` for proper Node.js module exports - Applied fixes to: - spec/dummy/config/webpack/serverWebpackConfig.js - lib/generators/.../serverWebpackConfig.js.tt (generator template) - react_on_rails_pro/spec/execjs-compatible-dummy/config/webpack/serverWebpackConfig.js React 19's react-dom/server includes Node.js-specific code that requires target: 'node' to work properly. Without this, webpack tries to bundle Node.js built-in modules and fails. Fixes build failures in CI: - examples (3.4, latest) - examples (3.2, minimum) - build-dummy-app-webpack-test-bundles 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 7c35cdb commit 57a49ad

File tree

7 files changed

+106
-11
lines changed

7 files changed

+106
-11
lines changed

lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ const configureServer = () => {
5050
serverWebpackConfig.output = {
5151
filename: 'server-bundle.js',
5252
globalObject: 'this',
53-
// If using the React on Rails Pro node server renderer, uncomment the next line
54-
// libraryTarget: 'commonjs2',
53+
// React 19 requires commonjs2 for proper Node.js module resolution
54+
libraryTarget: 'commonjs2',
5555
path: require('path').resolve(__dirname, '../../ssr-generated'),
5656
// No publicPath needed since server bundles are not served via web
5757
// https://webpack.js.org/configuration/output/#outputglobalobject
@@ -111,8 +111,8 @@ const configureServer = () => {
111111

112112
// If using the default 'web', then libraries like Emotion and loadable-components
113113
// break with SSR. The fix is to use a node renderer and change the target.
114-
// If using the React on Rails Pro node server renderer, uncomment the next line
115-
// serverWebpackConfig.target = 'node'
114+
// React 19 requires target: 'node' to properly handle Node.js built-in modules
115+
serverWebpackConfig.target = 'node';
116116

117117
// React 19 Fix: Prevent webpack from resolving to react-server condition
118118
// The server-bundle needs the full React with hooks for SSR, not the react-server build

react_on_rails_pro/spec/dummy/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"@babel/preset-typescript": "^7.23.2",
8080
"@playwright/test": "^1.56.1",
8181
"@pmmmwh/react-refresh-webpack-plugin": "0.5.3",
82+
"@swc/core": "^1.15.0",
8283
"@tailwindcss/aspect-ratio": "^0.4.2",
8384
"@tailwindcss/forms": "^0.5.3",
8485
"@tailwindcss/typography": "^0.5.9",
@@ -88,6 +89,7 @@
8889
"jsdom": "^16.4.0",
8990
"pino-pretty": "^13.0.0",
9091
"preload-webpack-plugin": "^3.0.0-alpha.1",
92+
"swc-loader": "^0.2.6",
9193
"typescript": "^5.2.2",
9294
"webpack-dev-server": "^4.7.3"
9395
},

react_on_rails_pro/spec/execjs-compatible-dummy/config/webpack/serverWebpackConfig.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ const configureServer = () => {
4949
filename: 'server-bundle.js',
5050
globalObject: 'this',
5151
// If using the React on Rails Pro node server renderer, uncomment the next line
52-
// libraryTarget: 'commonjs2',
52+
// React 19 requires commonjs2 for proper Node.js module resolution
53+
libraryTarget: 'commonjs2',
5354
path: config.outputPath,
5455
publicPath: config.publicPath,
5556
// https://webpack.js.org/configuration/output/#outputglobalobject
@@ -109,8 +110,8 @@ const configureServer = () => {
109110

110111
// If using the default 'web', then libraries like Emotion and loadable-components
111112
// break with SSR. The fix is to use a node renderer and change the target.
112-
// If using the React on Rails Pro node server renderer, uncomment the next line
113-
// serverWebpackConfig.target = 'node'
113+
// React 19 requires target: 'node' to properly handle Node.js built-in modules
114+
serverWebpackConfig.target = 'node';
114115

115116
// React 19 Fix: Prevent webpack from resolving to react-server condition
116117
// The server-bundle needs the full React with hooks for SSR, not the react-server build

react_on_rails_pro/spec/execjs-compatible-dummy/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
},
4545
"devDependencies": {
4646
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
47+
"@swc/core": "^1.15.0",
4748
"react-refresh": "^0.14.2",
49+
"swc-loader": "^0.2.6",
4850
"webpack-dev-server": "4"
4951
}
5052
}

spec/dummy/config/webpack/serverWebpackConfig.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ const configureServer = () => {
4545
serverWebpackConfig.output = {
4646
filename: 'server-bundle.js',
4747
globalObject: 'this',
48-
// If using the React on Rails Pro node server renderer, uncomment the next line
49-
// libraryTarget: 'commonjs2',
48+
// React 19 requires commonjs2 for proper Node.js module resolution
49+
libraryTarget: 'commonjs2',
5050
path: config.outputPath,
5151
publicPath: config.publicPath,
5252
// https://webpack.js.org/configuration/output/#outputglobalobject
@@ -107,8 +107,8 @@ const configureServer = () => {
107107

108108
// If using the default 'web', then libraries like Emotion and loadable-components
109109
// break with SSR. The fix is to use a node renderer and change the target.
110-
// If using the React on Rails Pro node server renderer, uncomment the next line
111-
// serverWebpackConfig.target = 'node'
110+
// React 19 requires target: 'node' to properly handle Node.js built-in modules
111+
serverWebpackConfig.target = 'node';
112112

113113
// React 19 Fix: Prevent webpack from resolving to react-server condition
114114
// The server-bundle needs the full React with hooks for SSR, not the react-server build

spec/dummy/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@babel/preset-react": "^7.10.4",
3636
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.1",
3737
"@rescript/react": "^0.13.0",
38+
"@swc/core": "^1.15.0",
3839
"@types/react": "^19.0.0",
3940
"@types/react-dom": "^19.0.0",
4041
"@types/react-helmet": "^6.1.5",
@@ -53,6 +54,7 @@
5354
"sass-resources-loader": "^2.1.0",
5455
"shakapacker": "9.3.0",
5556
"style-loader": "^3.3.1",
57+
"swc-loader": "^0.2.6",
5658
"terser-webpack-plugin": "5.3.1",
5759
"url-loader": "^4.0.0",
5860
"webpack": "5.72.0",

spec/dummy/yarn.lock

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,87 @@
13621362
dependencies:
13631363
"@sinonjs/commons" "^3.0.0"
13641364

1365+
1366+
version "1.15.0"
1367+
resolved "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.15.0.tgz#158a0890fb2546b4d57b99234c1033e4a38b62e2"
1368+
integrity sha512-TBKWkbnShnEjlIbO4/gfsrIgAqHBVqgPWLbWmPdZ80bF393yJcLgkrb7bZEnJs6FCbSSuGwZv2rx1jDR2zo6YA==
1369+
1370+
1371+
version "1.15.0"
1372+
resolved "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.15.0.tgz#d03a71e60244f19ac921bf23c2cafc4122d76d8e"
1373+
integrity sha512-f5JKL1v1H56CIZc1pVn4RGPOfnWqPwmuHdpf4wesvXunF1Bx85YgcspW5YxwqG5J9g3nPU610UFuExJXVUzOiQ==
1374+
1375+
1376+
version "1.15.0"
1377+
resolved "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.15.0.tgz#fe978712a8924c0555c6b248ad3b57912ba123fb"
1378+
integrity sha512-duK6nG+WyuunnfsfiTUQdzC9Fk8cyDLqT9zyXvY2i2YgDu5+BH5W6wM5O4mDNCU5MocyB/SuF5YDF7XySnowiQ==
1379+
1380+
1381+
version "1.15.0"
1382+
resolved "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.15.0.tgz#a5dacdd857dec4ac2931820def17bc0e42c88ede"
1383+
integrity sha512-ITe9iDtTRXM98B91rvyPP6qDVbhUBnmA/j4UxrHlMQ0RlwpqTjfZYZkD0uclOxSZ6qIrOj/X5CaoJlDUuQ0+Cw==
1384+
1385+
1386+
version "1.15.0"
1387+
resolved "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.15.0.tgz#243643a7d22c8e2f334046c1d76f342ad4369be9"
1388+
integrity sha512-Q5ldc2bzriuzYEoAuqJ9Vr3FyZhakk5hiwDbniZ8tlEXpbjBhbOleGf9/gkhLaouDnkNUEazFW9mtqwUTRdh7Q==
1389+
1390+
1391+
version "1.15.0"
1392+
resolved "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.15.0.tgz#26936f55c916f65d33a4cf957c7573722f9eca54"
1393+
integrity sha512-pY4is+jEpOxlYCSnI+7N8Oxbap9TmTz5YT84tUvRTlOlTBwFAUlWFCX0FRwWJlsfP0TxbqhIe8dNNzlsEmJbXQ==
1394+
1395+
1396+
version "1.15.0"
1397+
resolved "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.15.0.tgz#a7164c11ac86ed99a1d5d8bef86ec0fbe6235f6c"
1398+
integrity sha512-zYEt5eT8y8RUpoe7t5pjpoOdGu+/gSTExj8PV86efhj6ugB3bPlj3Y85ogdW3WMVXr4NvwqvzdaYGCZfXzSyVg==
1399+
1400+
1401+
version "1.15.0"
1402+
resolved "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.15.0.tgz#645fe54564eab4224127672f2f4fe44876223af0"
1403+
integrity sha512-zC1rmOgFH5v2BCbByOazEqs0aRNpTdLRchDExfcCfgKgeaD+IdpUOqp7i3VG1YzkcnbuZjMlXfM0ugpt+CddoA==
1404+
1405+
1406+
version "1.15.0"
1407+
resolved "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.15.0.tgz#fd70c8c8b542a52a88cda758fb82569d52ea949a"
1408+
integrity sha512-7t9U9KwMwQblkdJIH+zX1V4q1o3o41i0HNO+VlnAHT5o+5qHJ963PHKJ/pX3P2UlZnBCY465orJuflAN4rAP9A==
1409+
1410+
1411+
version "1.15.0"
1412+
resolved "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.15.0.tgz#1d4f06078c7dbf757c537dd08740472694257198"
1413+
integrity sha512-VE0Zod5vcs8iMLT64m5QS1DlTMXJFI/qSgtMDRx8rtZrnjt6/9NW8XUaiPJuRu8GluEO1hmHoyf1qlbY19gGSQ==
1414+
1415+
"@swc/core@^1.15.0":
1416+
version "1.15.0"
1417+
resolved "https://registry.npmjs.org/@swc/core/-/core-1.15.0.tgz#6ae4dbd5a164261ba799ccdf9eae3bbc61e112c2"
1418+
integrity sha512-8SnJV+JV0rYbfSiEiUvYOmf62E7QwsEG+aZueqSlKoxFt0pw333+bgZSQXGUV6etXU88nxur0afVMaINujBMSw==
1419+
dependencies:
1420+
"@swc/counter" "^0.1.3"
1421+
"@swc/types" "^0.1.25"
1422+
optionalDependencies:
1423+
"@swc/core-darwin-arm64" "1.15.0"
1424+
"@swc/core-darwin-x64" "1.15.0"
1425+
"@swc/core-linux-arm-gnueabihf" "1.15.0"
1426+
"@swc/core-linux-arm64-gnu" "1.15.0"
1427+
"@swc/core-linux-arm64-musl" "1.15.0"
1428+
"@swc/core-linux-x64-gnu" "1.15.0"
1429+
"@swc/core-linux-x64-musl" "1.15.0"
1430+
"@swc/core-win32-arm64-msvc" "1.15.0"
1431+
"@swc/core-win32-ia32-msvc" "1.15.0"
1432+
"@swc/core-win32-x64-msvc" "1.15.0"
1433+
1434+
"@swc/counter@^0.1.3":
1435+
version "0.1.3"
1436+
resolved "https://registry.npmjs.org/@swc/counter/-/counter-0.1.3.tgz#cc7463bd02949611c6329596fccd2b0ec782b0e9"
1437+
integrity sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==
1438+
1439+
"@swc/types@^0.1.25":
1440+
version "0.1.25"
1441+
resolved "https://registry.npmjs.org/@swc/types/-/types-0.1.25.tgz#b517b2a60feb37dd933e542d93093719e4cf1078"
1442+
integrity sha512-iAoY/qRhNH8a/hBvm3zKj9qQ4oc2+3w1unPJa2XvTK3XjeLXtzcCingVPw/9e5mn1+0yPqxcBGp9Jf0pkfMb1g==
1443+
dependencies:
1444+
"@swc/counter" "^0.1.3"
1445+
13651446
"@types/babel__core@^7.1.14":
13661447
version "7.20.5"
13671448
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.20.5.tgz#3df15f27ba85319caa07ba08d0721889bb39c017"
@@ -5968,6 +6049,13 @@ supports-preserve-symlinks-flag@^1.0.0:
59686049
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
59696050
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==
59706051

6052+
swc-loader@^0.2.6:
6053+
version "0.2.6"
6054+
resolved "https://registry.npmjs.org/swc-loader/-/swc-loader-0.2.6.tgz#bf0cba8eeff34bb19620ead81d1277fefaec6bc8"
6055+
integrity sha512-9Zi9UP2YmDpgmQVbyOPJClY0dwf58JDyDMQ7uRc4krmc72twNI2fvlBWHLqVekBpPc7h5NJkGVT1zNDxFrqhvg==
6056+
dependencies:
6057+
"@swc/counter" "^0.1.3"
6058+
59716059
symbol-observable@^1.2.0:
59726060
version "1.2.0"
59736061
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"

0 commit comments

Comments
 (0)