Skip to content

Commit d4662e5

Browse files
committed
fix(nextjs): handle case where conditionNames doesn't exist
If conditionNames is not set, use webpack's default conditions with 'development' prepended. This ensures Spotlight works even when Next.js doesn't initialize conditionNames.
1 parent 102dc61 commit d4662e5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,16 @@ export function constructWebpackConfigFunction({
9999

100100
// In development mode, add 'development' to resolve conditions so that
101101
// @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];
102+
if (isDev) {
103+
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 (webpack defaults + development)
110+
newConfig.resolve.conditionNames = ['development', 'webpack', 'module', 'import', 'require', 'default'];
111+
}
105112
}
106113

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

0 commit comments

Comments
 (0)