Skip to content

Commit 102dc61

Browse files
committed
fix(nextjs): preserve existing conditionNames when adding development
Only prepend 'development' to existing conditionNames if they exist, preserving Next.js's original ESM/CJS resolution behavior. This avoids the 'export *' client boundary error while still enabling SDK development features like Spotlight auto-enablement.
1 parent 5df223a commit 102dc61

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

dev-packages/e2e-tests/test-applications/nextjs-15-spotlight/next.config.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,6 @@ const nextConfig = {
77
env: {
88
NEXT_PUBLIC_SENTRY_SPOTLIGHT: 'true',
99
},
10-
11-
// Configure webpack to use 'development' export condition in dev mode
12-
// This enables Sentry SDK's development-only features like Spotlight auto-enablement
13-
// Note: This is required because Next.js doesn't use the 'development' condition by default
14-
webpack: (config, { dev }) => {
15-
if (dev) {
16-
config.resolve = config.resolve || {};
17-
config.resolve.conditionNames = [
18-
'development',
19-
...(config.resolve.conditionNames || ['import', 'module', 'browser', 'require', 'node', 'default']),
20-
];
21-
}
22-
return config;
23-
},
2410
};
2511

2612
module.exports = withSentryConfig(nextConfig, {

packages/nextjs/src/config/webpack.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +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+
// We only prepend 'development' to existing conditions to preserve Next.js's ESM/CJS resolution behavior
103+
if (isDev && newConfig.resolve?.conditionNames && !newConfig.resolve.conditionNames.includes('development')) {
104+
newConfig.resolve.conditionNames = ['development', ...newConfig.resolve.conditionNames];
105+
}
106+
100107
// Add a loader which will inject code that sets global values
101108
addValueInjectionLoader({
102109
newConfig,

0 commit comments

Comments
 (0)