Skip to content

fix: Exclude cloudflare builtins from SSR environment #507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions sdk/src/vite/configPlugin.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ import enhancedResolve from "enhanced-resolve";
import { SSR_BRIDGE_PATH } from "../lib/constants.mjs";
import { builtinModules } from "node:module";

// port(justinvdm, 09 Jun 2025):
// https://github.com/cloudflare/workers-sdk/blob/d533f5ee7da69c205d8d5e2a5f264d2370fc612b/packages/vite-plugin-cloudflare/src/cloudflare-environment.ts#L123-L128
export const cloudflareBuiltInModules = [
"cloudflare:email",
"cloudflare:sockets",
"cloudflare:workers",
"cloudflare:workflows",
];

export const externalModules = [
...cloudflareBuiltInModules,
...builtinModules,
...builtinModules.map((m) => `node:${m}`),
];

export const configPlugin = ({
mode,
silent,
Expand Down Expand Up @@ -72,7 +87,7 @@ export const configPlugin = ({
optimizeDeps: {
noDiscovery: false,
entries: [workerEntryPathname],
exclude: ["cloudflare:workers", ...builtinModules],
exclude: externalModules,
include: ["rwsdk/__ssr_bridge"],
esbuildOptions: {
jsx: "automatic",
Expand Down Expand Up @@ -149,20 +164,6 @@ export const configPlugin = ({
},
};

if (command === "build") {
return mergeConfig(baseConfig, {
environments: {
worker: {
build: {
rollupOptions: {
external: ["cloudflare:workers", "node:stream"],
},
},
},
},
});
}

return baseConfig;
},
});