Skip to content

Commit 568fbdc

Browse files
logaretmclaude
andcommitted
fix(nitro): Use console instead of debug logger for build-time messages
`configureSourcemapSettings` runs at build time, but the `debug` logger from `@sentry/core` is only initialized by `Sentry.init()` at runtime. Switch to `console.warn`/`console.log` so build-time warnings (e.g. source maps explicitly disabled) are actually visible to developers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f8c94fe commit 568fbdc

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

packages/nitro/src/sourceMaps.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Options as BundlerPluginOptions } from '@sentry/bundler-plugin-core';
22
import { createSentryBuildPluginManager } from '@sentry/bundler-plugin-core';
3-
import { debug } from '@sentry/core';
43
import type { Nitro, NitroConfig } from 'nitro/types';
54
import type { SentryNitroOptions } from './config';
65

@@ -107,21 +106,26 @@ export function configureSourcemapSettings(config: NitroConfig, moduleOptions?:
107106
}
108107

109108
if (config.sourcemap === false) {
110-
debug.warn(
111-
'[Sentry] You have explicitly disabled source maps (`sourcemap: false`). Sentry will not upload source maps, and errors will not be unminified. To let Sentry handle source maps, remove the `sourcemap` option from your Nitro config, or use `sourcemaps: { disable: true }` in your Sentry options to silence this warning.',
109+
// eslint-disable-next-line no-console
110+
console.warn(
111+
'[@sentry/nitro] You have explicitly disabled source maps (`sourcemap: false`). Sentry will not upload source maps, and errors will not be unminified. To let Sentry handle source maps, remove the `sourcemap` option from your Nitro config, or use `sourcemaps: { disable: true }` in your Sentry options to silence this warning.',
112112
);
113113
return;
114114
}
115115

116116
if (config.sourcemap === true) {
117117
if (moduleOptions?.debug) {
118-
debug.log('[Sentry] Source maps are already enabled. Sentry will upload them for error unminification.');
118+
// eslint-disable-next-line no-console
119+
console.log('[@sentry/nitro] Source maps are already enabled. Sentry will upload them for error unminification.');
119120
}
120121
} else {
121122
// User did not explicitly set sourcemap — enable it for Sentry
122123
config.sourcemap = true;
123124
if (moduleOptions?.debug) {
124-
debug.log('[Sentry] Enabled source map generation for Sentry. Source map files will be deleted after upload.');
125+
// eslint-disable-next-line no-console
126+
console.log(
127+
'[@sentry/nitro] Enabled source map generation for Sentry. Source map files will be deleted after upload.',
128+
);
125129
}
126130
}
127131

packages/nitro/test/sourceMaps.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { debug } from '@sentry/core';
21
import type { NitroConfig } from 'nitro/types';
32
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
43
import type { SentryNitroOptions } from '../src/config';
@@ -143,17 +142,17 @@ describe('configureSourcemapSettings', () => {
143142
});
144143

145144
it('respects user explicitly disabling sourcemaps and warns', () => {
146-
const debugSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
145+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
147146
const config: NitroConfig = { sourcemap: false };
148147
configureSourcemapSettings(config);
149148

150149
expect(config.sourcemap).toBe(false);
151-
expect(debugSpy).toHaveBeenCalledWith(expect.stringContaining('explicitly disabled source maps'));
152-
debugSpy.mockRestore();
150+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('explicitly disabled source maps'));
151+
warnSpy.mockRestore();
153152
});
154153

155154
it('does not modify experimental config when user disabled sourcemaps', () => {
156-
vi.spyOn(debug, 'warn').mockImplementation(() => {});
155+
vi.spyOn(console, 'warn').mockImplementation(() => {});
157156
const config: NitroConfig = { sourcemap: false };
158157
configureSourcemapSettings(config);
159158

0 commit comments

Comments
 (0)