File tree 2 files changed +38
-0
lines changed
packages/astro/src/integration
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';
4
4
import { sentryVitePlugin } from '@sentry/vite-plugin' ;
5
5
import type { AstroConfig , AstroIntegration } from 'astro' ;
6
6
7
+ import { namespaceBuiltinPlugin } from './namespace' ;
7
8
import { buildClientSnippet , buildSdkInitFileImportSnippet , buildServerSnippet } from './snippets' ;
8
9
import type { SentryOptions } from './types' ;
9
10
@@ -51,6 +52,17 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
51
52
} ) ;
52
53
}
53
54
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
+
54
66
const pathToClientInit = options . clientInitPath
55
67
? path . resolve ( options . clientInitPath )
56
68
: 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