diff --git a/packages/astro/src/integration/index.ts b/packages/astro/src/integration/index.ts index bdf2cf8f0ede..0ee4b3676590 100644 --- a/packages/astro/src/integration/index.ts +++ b/packages/astro/src/integration/index.ts @@ -80,6 +80,19 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { options.debug && logger.info('Using default server init.'); injectScript('page-ssr', buildServerSnippet(options || {})); } + + // Prevent Sentry from being externalized for SSR. + // Cloudflare like environments have Node.js APIs are available under `node:` prefix. + // Ref: https://developers.cloudflare.com/workers/runtime-apis/nodejs/ + if (config?.adapter?.name.startsWith('@astro/cloudflare')) { + updateConfig({ + vite: { + ssr: { + noExternal: ['@sentry/astro', '@sentry/node'], + }, + }, + }); + } } const isSSR = config && (config.output === 'server' || config.output === 'hybrid');