File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
packages/astro/src/integration Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import * as path from 'path';
44import { sentryVitePlugin } from '@sentry/vite-plugin' ;
55import type { AstroConfig , AstroIntegration } from 'astro' ;
66
7+ import { namespaceBuiltinPlugin } from './namespace' ;
78import { buildClientSnippet , buildSdkInitFileImportSnippet , buildServerSnippet } from './snippets' ;
89import type { SentryOptions } from './types' ;
910
@@ -51,6 +52,17 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
5152 } ) ;
5253 }
5354
55+ // Update Node.js builtin imports for Cloudflare.
56+ // Node.js APIs are available under `node:` prefix.
57+ // Ref: https://developers.cloudflare.com/workers/runtime-apis/nodejs/
58+ if ( config ?. adapter ?. name . startsWith ( '@astrojs/cloudflare' ) ) {
59+ updateConfig ( {
60+ vite : {
61+ plugins : [ namespaceBuiltinPlugin ( ) ] ,
62+ } ,
63+ } ) ;
64+ }
65+
5466 const pathToClientInit = options . clientInitPath
5567 ? path . resolve ( options . clientInitPath )
5668 : findDefaultSdkInitFile ( 'client' ) ;
Original file line number Diff line number Diff line change 1+ import module from 'module' ;
2+ import type { Plugin } from 'vite' ;
3+
4+ /**
5+ * Cloudflare like environments doesn't support requiring builtin modules
6+ * to be loaded without `node:` prefix. This vite plugin ensures that,
7+ * all built-in modules are loaded with `node:` prefix.
8+ *
9+ * TODO: Remove this when we support Node 18 and above.
10+ */
11+ export function namespaceBuiltinPlugin ( ) : Plugin {
12+ return {
13+ name : 'sentry-builtin-namespace' ,
14+ enforce : 'pre' ,
15+ resolveId ( id ) {
16+ if ( module . builtinModules . includes ( id ) ) {
17+ return {
18+ id : `node:${ id } ` ,
19+ external : true ,
20+ } ;
21+ }
22+
23+ return undefined ;
24+ } ,
25+ } ;
26+ }
You can’t perform that action at this time.
0 commit comments