Skip to content

Commit a3dfde6

Browse files
authored
fix(sveltekit): Explicitly export Node SDK exports (#7644)
Fix Node SDK exports not being available in prod builds. For example, calling `Sentry.withScope(...)` throws an error because `withScope` is not defined on the top-level namespace. This is because for CJS, Vite puts wildcard-exported properties into the `default` property rather than onto the namespace in production builds.
1 parent 120ae6d commit a3dfde6

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
11
export * from './client';
2-
3-
/**
4-
* This const serves no purpose besides being an identifier for this file that the SDK multiplexer loader can use to
5-
* determine that this is in fact a file that wants to be multiplexed.
6-
*/
7-
export const _SENTRY_SDK_MULTIPLEXER = true;
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
11
export * from './server';
22
export * from './config';
3-
4-
// This file is the main entrypoint on the server and/or when the package is `require`d
5-
6-
/**
7-
* This const serves no purpose besides being an identifier for this file that the SDK multiplexer loader can use to
8-
* determine that this is in fact a file that wants to be multiplexed.
9-
*/
10-
export const _SENTRY_SDK_MULTIPLEXER = true;

packages/sveltekit/src/server/index.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,55 @@
1+
// Node SDK exports
2+
// Unfortunately, we cannot `exprt * from '@sentry/node'` because in prod builds,
3+
// Vite puts these exports into a `default` property (Sentry.default) rather than
4+
// on the top - level namespace.
5+
// Hence, we export everything from the Node SDK explicitly:
6+
export {
7+
addGlobalEventProcessor,
8+
addBreadcrumb,
9+
captureException,
10+
captureEvent,
11+
captureMessage,
12+
configureScope,
13+
createTransport,
14+
extractTraceparentData,
15+
getActiveTransaction,
16+
getHubFromCarrier,
17+
getCurrentHub,
18+
Hub,
19+
makeMain,
20+
Scope,
21+
startTransaction,
22+
SDK_VERSION,
23+
setContext,
24+
setExtra,
25+
setExtras,
26+
setTag,
27+
setTags,
28+
setUser,
29+
spanStatusfromHttpCode,
30+
trace,
31+
withScope,
32+
autoDiscoverNodePerformanceMonitoringIntegrations,
33+
makeNodeTransport,
34+
defaultIntegrations,
35+
defaultStackParser,
36+
lastEventId,
37+
flush,
38+
close,
39+
getSentryRelease,
40+
addRequestDataToEvent,
41+
DEFAULT_USER_INCLUDES,
42+
extractRequestData,
43+
deepReadDirSync,
44+
Integrations,
45+
Handlers,
46+
} from '@sentry/node';
47+
48+
// We can still leave this for the carrier init and type exports
149
export * from '@sentry/node';
250

51+
// -------------------------
52+
// SvelteKit SDK exports:
353
export { init } from './sdk';
454
export { handleErrorWithSentry } from './handleError';
555
export { wrapLoadWithSentry } from './load';

0 commit comments

Comments
 (0)