diff --git a/packages/astro/src/integration/index.ts b/packages/astro/src/integration/index.ts index 213fae64ed7a..e2d177e2b575 100644 --- a/packages/astro/src/integration/index.ts +++ b/packages/astro/src/integration/index.ts @@ -14,7 +14,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { name: PKG_NAME, hooks: { // eslint-disable-next-line complexity - 'astro:config:setup': async ({ updateConfig, injectScript, addMiddleware, config }) => { + 'astro:config:setup': async ({ updateConfig, injectScript, addMiddleware, config, command }) => { // The third param here enables loading of all env vars, regardless of prefix // see: https://main.vitejs.dev/config/#using-environment-variables-in-config @@ -29,7 +29,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { const shouldUploadSourcemaps = uploadOptions?.enabled ?? true; // We don't need to check for AUTH_TOKEN here, because the plugin will pick it up from the env - if (shouldUploadSourcemaps) { + if (shouldUploadSourcemaps && command !== 'dev') { updateConfig({ vite: { build: { diff --git a/packages/astro/test/integration/index.test.ts b/packages/astro/test/integration/index.test.ts index 7dba9a0ef347..5b8be17496c0 100644 --- a/packages/astro/test/integration/index.test.ts +++ b/packages/astro/test/integration/index.test.ts @@ -155,6 +155,19 @@ describe('sentryAstro integration', () => { expect(sentryVitePluginSpy).toHaveBeenCalledTimes(0); }); + it("doesn't add the Vite plugin in dev mode", async () => { + const integration = sentryAstro({ + sourceMapsUploadOptions: { enabled: true }, + }); + + expect(integration.hooks['astro:config:setup']).toBeDefined(); + // @ts-expect-error - the hook exists and we only need to pass what we actually use + await integration.hooks['astro:config:setup']({ updateConfig, injectScript, config, command: 'dev' }); + + expect(updateConfig).toHaveBeenCalledTimes(0); + expect(sentryVitePluginSpy).toHaveBeenCalledTimes(0); + }); + it('injects client and server init scripts', async () => { const integration = sentryAstro({});