Skip to content

Commit 3f7e452

Browse files
justin808claude
andcommitted
Use externals instead of fallbacks for Node builtins in server bundle
The server bundle runs in Node.js, so use externals to resolve path, fs, stream at runtime via require() instead of replacing them with empty modules. This avoids potential runtime crashes when react-on-rails-pro RSC modules are imported transitively. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 92306ff commit 3f7e452

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

config/webpack/serverWebpackConfig.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,15 @@ const configureServer = () => {
172172
};
173173

174174
// react-on-rails-pro includes RSC-related modules that import Node.js builtins
175-
// (path, fs, stream). These code paths aren't used in the traditional SSR bundle,
176-
// so provide empty fallbacks to avoid resolution errors.
177-
serverWebpackConfig.resolve.fallback = {
178-
...serverWebpackConfig.resolve.fallback,
179-
path: false,
180-
fs: false,
181-
'fs/promises': false,
182-
stream: false,
175+
// (path, fs, stream). Externalize them so they resolve at runtime via require()
176+
// in the Node.js environment where the SSR bundle executes.
177+
const existingExternals = serverWebpackConfig.externals || {};
178+
serverWebpackConfig.externals = {
179+
...(typeof existingExternals === 'object' && !Array.isArray(existingExternals) ? existingExternals : {}),
180+
path: 'commonjs path',
181+
fs: 'commonjs fs',
182+
'fs/promises': 'commonjs fs/promises',
183+
stream: 'commonjs stream',
183184
};
184185

185186
return serverWebpackConfig;

0 commit comments

Comments
 (0)