Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/nextjs/src/config/withSentryConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,16 @@ function migrateDeprecatedWebpackOptions(userSentryOptions: SentryBuildOptions):
return newValue ?? deprecatedValue;
};

const deprecatedMessage = (deprecatedPath: string, newPath: string): string =>
`[@sentry/nextjs] DEPRECATION WARNING: ${deprecatedPath} is deprecated and will be removed in a future version. Use ${newPath} instead.`;
const deprecatedMessage = (deprecatedPath: string, newPath: string): string => {
const message = `[@sentry/nextjs] DEPRECATION WARNING: ${deprecatedPath} is deprecated and will be removed in a future version. Use ${newPath} instead.`;

// In Turbopack builds, webpack configuration is not applied, so webpack-scoped options won't have any effect.
if (detectActiveBundler() === 'turbopack' && newPath.startsWith('webpack.')) {
return `${message} (Not supported with Turbopack.)`;
}

return message;
};

/* eslint-disable deprecation/deprecation */
// Migrate each deprecated option to the new path, but only if the new path isn't already set
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The bundler detection logic checks for the --turbo CLI flag, but the correct flag used by Next.js is --turbopack, causing detection to fail.
Severity: HIGH

🔍 Detailed Analysis

The detectActiveBundler() function attempts to detect if Turbopack is being used by checking if process.argv includes '--turbo'. However, the correct command-line flag for enabling Turbopack in Next.js is '--turbopack'. This discrepancy means that when a user runs a build with the --turbopack flag (and without the TURBOPACK environment variable set), the system will fail to identify Turbopack. As a result, deprecation warnings for webpack-specific options will be missing the "(Not supported with Turbopack.)" note, providing incorrect feedback to the user.

💡 Suggested Fix

In packages/nextjs/src/config/util.ts, update the detectActiveBundler function. Change the condition process.argv.includes('--turbo') to process.argv.includes('--turbopack') to correctly detect when Turbopack is enabled via the command-line interface.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: packages/nextjs/src/config/withSentryConfig.ts#L137

Potential issue: The `detectActiveBundler()` function attempts to detect if Turbopack is
being used by checking if `process.argv` includes `'--turbo'`. However, the correct
command-line flag for enabling Turbopack in Next.js is `'--turbopack'`. This discrepancy
means that when a user runs a build with the `--turbopack` flag (and without the
`TURBOPACK` environment variable set), the system will fail to identify Turbopack. As a
result, deprecation warnings for webpack-specific options will be missing the "(Not
supported with Turbopack.)" note, providing incorrect feedback to the user.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 8466916

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it checks for .includes so this covers both cases

Expand Down
15 changes: 15 additions & 0 deletions packages/nextjs/test/config/withSentryConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,21 @@ describe('withSentryConfig', () => {
);
});

it('adds a turbopack note when the deprecated option only applies to webpack', () => {
process.env.TURBOPACK = '1';
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('16.0.0');

const sentryOptions = {
disableLogger: true,
};

materializeFinalNextConfig(exportedNextConfig, undefined, sentryOptions);

expect(consoleWarnSpy).toHaveBeenCalledWith(
expect.stringContaining('Use webpack.treeshake.removeDebugLogging instead. (Not supported with Turbopack.)'),
);
});

it('does not warn when using new webpack path', () => {
delete process.env.TURBOPACK;

Expand Down
Loading