Skip to content

Commit dde88ca

Browse files
committed
fix(nextjs): use resolve.alias to point @sentry/browser to dev build
Instead of modifying conditionNames (which wasn't working reliably), use webpack's resolve.alias to explicitly point @sentry/browser to its CJS development build for client bundles in dev mode. This enables Spotlight auto-enablement from env vars in Next.js dev mode.
1 parent 7cffb67 commit dde88ca

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -97,27 +97,13 @@ export function constructWebpackConfigFunction({
9797
// `newConfig.module.rules` is required, so we don't have to keep asserting its existence
9898
const newConfig = setUpModuleRules(rawNewConfig);
9999

100-
// In development mode, add 'development' to resolve conditions so that
101-
// @sentry/* packages use their development exports (which include features like Spotlight auto-enablement)
102-
if (isDev) {
100+
// In development mode for client bundles, alias @sentry/browser to its development build
101+
// This enables development-only features like Spotlight auto-enablement from env vars
102+
if (isDev && !isServer) {
103103
newConfig.resolve = newConfig.resolve || {};
104-
const existingConditions = newConfig.resolve.conditionNames;
105-
if (existingConditions && !existingConditions.includes('development')) {
106-
// Prepend 'development' to existing conditions to preserve Next.js's ESM/CJS resolution
107-
newConfig.resolve.conditionNames = ['development', ...existingConditions];
108-
} else if (!existingConditions) {
109-
// Set default conditions with 'development' first
110-
// Include 'browser' for client bundles, 'node' for server bundles
111-
const platformCondition = isServer ? 'node' : 'browser';
112-
newConfig.resolve.conditionNames = [
113-
'development',
114-
platformCondition,
115-
'module',
116-
'import',
117-
'require',
118-
'default',
119-
];
120-
}
104+
newConfig.resolve.alias = newConfig.resolve.alias || {};
105+
// Use the CJS development build to avoid ESM 'export *' issues in Next.js client boundaries
106+
newConfig.resolve.alias['@sentry/browser$'] = '@sentry/browser/build/npm/cjs/dev/index.js';
121107
}
122108

123109
// Add a loader which will inject code that sets global values

0 commit comments

Comments
 (0)