diff --git a/.changeset/heavy-pants-change.md b/.changeset/heavy-pants-change.md new file mode 100644 index 000000000000..32c7b30efe1a --- /dev/null +++ b/.changeset/heavy-pants-change.md @@ -0,0 +1,5 @@ +--- +'@astrojs/vercel': patch +--- + +Fix react-dom on Vercel edge diff --git a/packages/integrations/vercel/src/edge/adapter.ts b/packages/integrations/vercel/src/edge/adapter.ts index 84ecd7395265..14dac655d37e 100644 --- a/packages/integrations/vercel/src/edge/adapter.ts +++ b/packages/integrations/vercel/src/edge/adapter.ts @@ -32,8 +32,17 @@ export default function vercelEdge(): AstroIntegration { if (target === 'server') { vite.resolve ||= {}; vite.resolve.alias ||= {}; - const alias = vite.resolve.alias as Record; - alias['react-dom/server'] = 'react-dom/server.browser'; + + const aliases = [{ find: 'react-dom/server', replacement: 'react-dom/server.browser' }]; + + if (Array.isArray(vite.resolve.alias)) { + vite.resolve.alias = [...vite.resolve.alias, ...aliases]; + } else { + for (const alias of aliases) { + (vite.resolve.alias as Record)[alias.find] = alias.replacement; + } + } + vite.ssr = { noExternal: true, };