Skip to content

Commit a8fb0da

Browse files
justin808claude
andcommitted
Fix ExecJS compatibility: remove libraryTarget commonjs2 for default setup
Root cause: Setting libraryTarget: 'commonjs2' creates bundles that require Node.js's require() function, which is not available in ExecJS (the default server rendering engine). Changes: - Removed libraryTarget: 'commonjs2' from spec/dummy (uses ExecJS) - Removed libraryTarget: 'commonjs2' from execjs-compatible-dummy - Updated generator template with clear comments about when to use it - Kept target: 'node' to externalize Node.js built-in modules (required for React 19) The fix: - target: 'node' externalizes crypto, async_hooks, stream (✅ needed for React 19) - libraryTarget: 'commonjs2' only for Node renderer (❌ breaks ExecJS) Fixes CI errors: - TypeError: require is not a function (ExecJS evaluation error) - examples (3.4, latest) - examples (3.2, minimum) - dummy-app-integration-tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 57a49ad commit a8fb0da

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ const configureServer = () => {
5050
serverWebpackConfig.output = {
5151
filename: 'server-bundle.js',
5252
globalObject: 'this',
53-
// React 19 requires commonjs2 for proper Node.js module resolution
54-
libraryTarget: 'commonjs2',
53+
// Note: libraryTarget should only be 'commonjs2' when using Node renderer
54+
// For ExecJS (default), leave it undefined to allow proper evaluation
55+
// If using the React on Rails Pro node server renderer, uncomment the next line
56+
// libraryTarget: 'commonjs2',
5557
path: require('path').resolve(__dirname, '../../ssr-generated'),
5658
// No publicPath needed since server bundles are not served via web
5759
// https://webpack.js.org/configuration/output/#outputglobalobject

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ const configureServer = () => {
4848
serverWebpackConfig.output = {
4949
filename: 'server-bundle.js',
5050
globalObject: 'this',
51+
// Note: libraryTarget should only be 'commonjs2' when using Node renderer
52+
// For ExecJS (default), leave it undefined to allow proper evaluation
5153
// If using the React on Rails Pro node server renderer, uncomment the next line
52-
// React 19 requires commonjs2 for proper Node.js module resolution
53-
libraryTarget: 'commonjs2',
54+
// libraryTarget: 'commonjs2',
5455
path: config.outputPath,
5556
publicPath: config.publicPath,
5657
// https://webpack.js.org/configuration/output/#outputglobalobject

spec/dummy/config/webpack/serverWebpackConfig.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ const configureServer = () => {
4545
serverWebpackConfig.output = {
4646
filename: 'server-bundle.js',
4747
globalObject: 'this',
48-
// React 19 requires commonjs2 for proper Node.js module resolution
49-
libraryTarget: 'commonjs2',
48+
// Note: libraryTarget should only be 'commonjs2' when using Node renderer
49+
// For ExecJS (default), leave it undefined to allow proper evaluation
50+
// If using the React on Rails Pro node server renderer, uncomment the next line
51+
// libraryTarget: 'commonjs2',
5052
path: config.outputPath,
5153
publicPath: config.publicPath,
5254
// https://webpack.js.org/configuration/output/#outputglobalobject

0 commit comments

Comments
 (0)