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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

event-dumps

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

# Sentry Config File
.env.sentry-build-plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const dynamic = 'force-dynamic';

export function GET() {
throw new Error('nextjs-16-standalone-server-error');
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use client';

import * as Sentry from '@sentry/nextjs';
import NextError from 'next/error';
import { useEffect } from 'react';

export default function GlobalError({ error }: { error: Error & { digest?: string } }) {
useEffect(() => {
Sentry.captureException(error);
}, [error]);

return (
<html>
<body>
{/* `NextError` is the default Next.js error page component. Its type
definition requires a `statusCode` prop. However, since the App Router
does not expose status codes for errors, we simply pass 0 to render a
generic error message. */}
<NextError statusCode={0} />
</body>
</html>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const dynamic = 'force-dynamic';

export default function Page() {
return <p>Next.js 16 Standalone Output Test</p>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import { FlatCompat } from '@eslint/eslintrc';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname,
});

const eslintConfig = [
...compat.extends('next/core-web-vitals', 'next/typescript'),
{
ignores: ['node_modules/**', '.next/**', 'out/**', 'build/**', 'next-env.d.ts'],
},
];

export default eslintConfig;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as Sentry from '@sentry/nextjs';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.NEXT_PUBLIC_E2E_TEST_DSN,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1.0,
dataCollection: { userInfo: true },
});

export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as Sentry from '@sentry/nextjs';

export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('./sentry.server.config');
}

if (process.env.NEXT_RUNTIME === 'edge') {
await import('./sentry.edge.config');
}
}

export const onRequestError = Sentry.captureRequestError;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { withSentryConfig } from '@sentry/nextjs';
import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
output: 'standalone',
// Pin the tracing root to this app so the standalone server always ends up at
// .next/standalone/server.js, even when the app runs inside the SDK monorepo.
outputFileTracingRoot: __dirname,
};

export default withSentryConfig(nextConfig, {
silent: true,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "nextjs-16-standalone",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)",
"build-webpack": "next build --webpack > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)",
"copy-standalone-assets": "cp -r public .next/standalone/public && cp -r .next/static .next/standalone/.next/static",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"start": "node .next/standalone/server.js",
"lint": "eslint",
"test:prod": "TEST_ENV=production playwright test",
"test:build": "pnpm install && pnpm build && pnpm copy-standalone-assets",
"test:build-webpack": "pnpm install && pnpm build-webpack && pnpm copy-standalone-assets",
"test:build-canary": "pnpm install && pnpm add next@canary && pnpm build && pnpm copy-standalone-assets",
"test:build-latest": "pnpm install && pnpm add next@latest && pnpm build && pnpm copy-standalone-assets",
"test:assert": "pnpm test:prod"
},
"dependencies": {
"@sentry/nextjs": "file:../../packed/sentry-nextjs-packed.tgz",
"@sentry/core": "file:../../packed/sentry-core-packed.tgz",
"import-in-the-middle": "^2",
"next": "16.2.3",
"react": "19.1.0",
"react-dom": "19.1.0",
"require-in-the-middle": "^8"
},
"devDependencies": {
"@playwright/test": "~1.56.0",
"@sentry-internal/test-utils": "link:../../../test-utils",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "^16",
"typescript": "^5"
},
"volta": {
"extends": "../../package.json"
},
"sentryTest": {
"variants": [
{
"build-command": "pnpm test:build-webpack",
"label": "nextjs-16-standalone (webpack)",
"assert-command": "pnpm test:assert"
},
{
"build-command": "pnpm test:build",
"label": "nextjs-16-standalone (turbopack)",
"assert-command": "pnpm test:assert"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getPlaywrightConfig } from '@sentry-internal/test-utils';
const testEnv = process.env.TEST_ENV;

if (testEnv !== 'production') {
throw new Error(`Unknown test env: ${testEnv} - the standalone output only exists for production builds`);
}

const config = getPlaywrightConfig({
startCommand: 'PORT=3030 node .next/standalone/server.js',
port: 3030,
});

export default config;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as Sentry from '@sentry/nextjs';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.NEXT_PUBLIC_E2E_TEST_DSN,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1.0,
dataCollection: { userInfo: true },
// debug: true,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as Sentry from '@sentry/nextjs';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.NEXT_PUBLIC_E2E_TEST_DSN,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1.0,
dataCollection: { userInfo: true },
// debug: true,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as fs from 'fs';
import * as path from 'path';
import { startEventProxyServer } from '@sentry-internal/test-utils';

const packageJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json')));

startEventProxyServer({
port: 3031,
proxyServerName: 'nextjs-16-standalone',
envelopeDumpPath: path.join(
process.cwd(),
`event-dumps/nextjs-16-standalone-v${packageJson.dependencies.next}-${process.env.TEST_ENV}.dump`,
),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as fs from 'fs';
import * as path from 'path';
import { expect, test } from '@playwright/test';
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';

function findFileInDir(dir: string, suffix: string): string | undefined {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const entryPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
const found = findFileInDir(entryPath, suffix);
if (found) {
return found;
}
} else if (entryPath.endsWith(suffix)) {
return entryPath;
}
}
return undefined;
}

test('standalone output contains all meriyah files needed at runtime', () => {
// meriyah's ESM build sits behind the `module-sync` export condition, which Next.js' output file
// tracing resolves differently than the Node.js runtime does (https://github.com/vercel/nft/issues/603).
// Without the SDK force-including it, the standalone server crashes with ERR_MODULE_NOT_FOUND.
const standaloneDir = path.join(process.cwd(), '.next', 'standalone');
expect(findFileInDir(standaloneDir, path.join('meriyah', 'dist', 'meriyah.mjs'))).toBeDefined();
expect(findFileInDir(standaloneDir, path.join('meriyah', 'dist', 'meriyah.cjs'))).toBeDefined();
});

test('sends a server transaction from the standalone server', async ({ page }) => {
const transactionPromise = waitForTransaction('nextjs-16-standalone', transactionEvent => {
return transactionEvent.transaction === 'GET /';
});

await page.goto('/');

const transactionEvent = await transactionPromise;
expect(transactionEvent.contexts?.trace?.op).toBe('http.server');
});

test('captures an error thrown in a route handler', async ({ request }) => {
const errorEventPromise = waitForError('nextjs-16-standalone', errorEvent => {
return errorEvent.exception?.values?.some(value => value.value === 'nextjs-16-standalone-server-error') ?? false;
});

const transactionEventPromise = waitForTransaction('nextjs-16-standalone', transactionEvent => {
return (
transactionEvent.transaction === 'GET /api/server-error' && transactionEvent.contexts?.trace?.op === 'http.server'
);
});

request.get('/api/server-error').catch(() => {
// expected to fail
});

const errorEvent = await errorEventPromise;
const transactionEvent = await transactionEventPromise;

expect(errorEvent.exception?.values?.[0]?.value).toBe('nextjs-16-standalone-server-error');
expect(transactionEvent.contexts?.trace?.status).toBe('internal_error');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", ".next/dev/types/**/*.ts", "**/*.mts"],
"exclude": ["node_modules"]
}
2 changes: 2 additions & 0 deletions packages/nextjs/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ export type NextConfigObject = {
instrumentationHook?: boolean;
clientTraceMetadata?: string[];
serverComponentsExternalPackages?: string[]; // next < v15.0.0
outputFileTracingIncludes?: Record<string, string[]>; // next < v15.0.0
sri?: { algorithm?: string };
};
productionBrowserSourceMaps?: boolean;
// https://nextjs.org/docs/pages/api-reference/next-config-js/env
env?: Record<string, string>;
serverExternalPackages?: string[]; // next >= v15.0.0
outputFileTracingIncludes?: Record<string, string[]>; // next >= v15.0.0
turbopack?: TurbopackOptions;
compiler?: {
runAfterProductionCompile?: (context: { distDir: string; projectDir: string }) => Promise<void> | void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from './getFinalConfigObjectBundlerUtils';
import {
getNextMajor,
maybeAddOutputFileTracingIncludes,
maybeCreateRouteManifest,
maybeGetVercelCronsConfig,
maybeSetClientTraceMetadataOption,
Expand Down Expand Up @@ -53,6 +54,7 @@ export function getFinalConfigObject(

maybeSetClientTraceMetadataOption(incomingUserNextConfigObject, nextJsVersion);
maybeSetInstrumentationHookOption(incomingUserNextConfigObject, nextJsVersion);
maybeAddOutputFileTracingIncludes(incomingUserNextConfigObject, nextJsVersion);
warnIfMissingOnRouterTransitionStartHook(userSentryOptions);

const bundlerInfo = getBundlerInfo(nextJsVersion);
Expand Down
Loading
Loading