diff --git a/packages/nextjs/src/config/withSentryConfig.ts b/packages/nextjs/src/config/withSentryConfig.ts index 494052af26f2..35e8b3c1ed2d 100644 --- a/packages/nextjs/src/config/withSentryConfig.ts +++ b/packages/nextjs/src/config/withSentryConfig.ts @@ -62,6 +62,17 @@ export const DEFAULT_SERVER_EXTERNAL_PACKAGES = [ * @returns The modified config to be exported */ export function withSentryConfig(nextConfig?: C, sentryBuildOptions: SentryBuildOptions = {}): C { + if (process.env.npm_lifecycle_event && !process.env.npm_lifecycle_event.includes('build')) { + if (sentryBuildOptions.debug) { + // eslint-disable-next-line no-console + console.debug( + '[@sentry/nextjs] Exiting withSentryConfig because of non-build npm_lifecycle_event detected:', + process.env.npm_lifecycle_event, + ); + } + return nextConfig as C; + } + const castNextConfig = (nextConfig as NextConfig) || {}; if (typeof castNextConfig === 'function') { return function (this: unknown, ...webpackConfigFunctionArgs: unknown[]): ReturnType {