Skip to content

Commit cba2e73

Browse files
committed
guard with try/catch
1 parent 4e5737b commit cba2e73

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

packages/sveltekit/src/vite/sourceMaps.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,26 @@ export async function makeCustomSentryVitePlugins(options?: CustomSentryVitePlug
7676
const defaultFileDeletionGlob = ['./.*/**/*.map', `./${adapterOutputDir}/**/*.map`];
7777

7878
if (!globalWithSourceMapSetting._sentry_sourceMapSetting) {
79-
// @ts-expect-error - the dynamic import here works fine
80-
const Vite = await import('vite');
81-
const configFile = await Vite.loadConfigFromFile({ command: 'build', mode: 'production' });
79+
let configFile: {
80+
path: string;
81+
config: UserConfig;
82+
dependencies: string[];
83+
} | null = null;
84+
85+
try {
86+
// @ts-expect-error - the dynamic import here works fine
87+
const Vite = await import('vite');
88+
configFile = await Vite.loadConfigFromFile({ command: 'build', mode: 'production' });
89+
} catch {
90+
if (options?.debug) {
91+
consoleSandbox(() => {
92+
// eslint-disable-next-line no-console
93+
console.warn(
94+
'[Sentry] Could not import Vite to load your vite config. Please set `build.sourcemap` to `true` or `hidden` to enable source map generation.',
95+
);
96+
});
97+
}
98+
}
8299

83100
if (configFile) {
84101
globalWithSourceMapSetting._sentry_sourceMapSetting = getUpdatedSourceMapSetting(configFile.config);

0 commit comments

Comments
 (0)