Skip to content

Commit 3b7c41d

Browse files
chargomeclaude
andcommitted
ref(nextjs)!: Move withSentryConfig to @sentry/nextjs/config
The `node` export condition matches for any Node process and is declared before `import`, so a bare string pointing at the CJS build won every Node resolution and made the `import` entry below it unreachable. ESM consumers got the CJS build, where `cjs-module-lexer` cannot see the `export *` re-exports from `@sentry/core` and `@sentry/node`, leaving `captureException` and friends `undefined` on a namespace import. `node` could not simply be split, because the server entry also re-exported build-time config code that resolves webpack loader and template paths with `__dirname` — a `ReferenceError` in an ES module. Moving `withSentryConfig` and `SentryBuildOptions` to their own entry point takes that code out of the runtime graph and lets `node` split like every other condition already does. `./config` deliberately resolves to CommonJS under both conditions, since `next.config.mjs` is loaded by a plain Node ESM loader. This is safe because the module holds no SDK state. It also matches the other framework SDKs, which keep their build plugins on `./vite`, `./module` and `./middleware`. Drop the no-op `withSentryConfig` passthroughs from the client and edge builds: they only existed so the name stayed resolvable when Next compiled a module that imported it for those runtimes, which cannot happen now. Add the `.js` extension to the `next/constants` import. It sits in the runtime graph, and Node does no extension resolution for ESM, so it fails at link time once the ESM server build is the one actually loaded. BREAKING CHANGE: `withSentryConfig` and `SentryBuildOptions` are no longer exported from `@sentry/nextjs`. Import them from `@sentry/nextjs/config`. Fixes #22791 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 1718e70 commit 3b7c41d

31 files changed

Lines changed: 192 additions & 51 deletions

File tree

‎dev-packages/e2e-tests/test-applications/nextjs-14/next.config.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { withSentryConfig } = require('@sentry/nextjs');
1+
const { withSentryConfig } = require('@sentry/nextjs/config');
22

33
/** @type {import('next').NextConfig} */
44
const nextConfig = {};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { withSentryConfig } = require('@sentry/nextjs');
1+
const { withSentryConfig } = require('@sentry/nextjs/config');
22

33
/** @type {import('next').NextConfig} */
44
const nextConfig = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { withSentryConfig } = require('@sentry/nextjs');
1+
const { withSentryConfig } = require('@sentry/nextjs/config');
22
const createNextIntlPlugin = require('next-intl/plugin');
33

44
const withNextIntl = createNextIntlPlugin('./i18n/request.ts');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ await import('./src/env.js');
33
/** @type {import("next").NextConfig} */
44
const config = {};
55

6-
import { withSentryConfig } from '@sentry/nextjs';
6+
import { withSentryConfig } from '@sentry/nextjs/config';
77

88
export default withSentryConfig(config, {
99
webpack: {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { withSentryConfig } = require('@sentry/nextjs');
1+
const { withSentryConfig } = require('@sentry/nextjs/config');
22

33
// Simulate Vercel environment for cron monitoring tests
44
process.env.VERCEL = '1';

‎dev-packages/e2e-tests/test-applications/nextjs-16-bun/next.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { withSentryConfig } from '@sentry/nextjs';
1+
import { withSentryConfig } from '@sentry/nextjs/config';
22
import type { NextConfig } from 'next';
33

44
const nextConfig: NextConfig = {};

‎dev-packages/e2e-tests/test-applications/nextjs-16-cacheComponents/next.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { withSentryConfig } from '@sentry/nextjs';
1+
import { withSentryConfig } from '@sentry/nextjs/config';
22
import type { NextConfig } from 'next';
33

44
const nextConfig: NextConfig = {

‎dev-packages/e2e-tests/test-applications/nextjs-16-cf-workers/next.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { withSentryConfig } from '@sentry/nextjs';
1+
import { withSentryConfig } from '@sentry/nextjs/config';
22
import type { NextConfig } from 'next';
33

44
const nextConfig: NextConfig = {};

‎dev-packages/e2e-tests/test-applications/nextjs-16-streaming-cacheComponents/next.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { withSentryConfig } from '@sentry/nextjs';
1+
import { withSentryConfig } from '@sentry/nextjs/config';
22
import type { NextConfig } from 'next';
33

44
const nextConfig: NextConfig = {

‎dev-packages/e2e-tests/test-applications/nextjs-16-streaming/next.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { withSentryConfig } from '@sentry/nextjs';
1+
import { withSentryConfig } from '@sentry/nextjs/config';
22
import type { NextConfig } from 'next';
33

44
// Simulate Vercel environment for cron monitoring tests

0 commit comments

Comments
 (0)