Skip to content

fix: Update nextjs-app-router example for Next.js ^16 and TypeScript compatibility#374

Merged
amychisholm03 merged 4 commits into
mainfrom
NR-345/nextjs-turbopack-ts-fix
Jun 3, 2026
Merged

fix: Update nextjs-app-router example for Next.js ^16 and TypeScript compatibility#374
amychisholm03 merged 4 commits into
mainfrom
NR-345/nextjs-turbopack-ts-fix

Conversation

@amychisholm03

@amychisholm03 amychisholm03 commented May 19, 2026

Copy link
Copy Markdown
Contributor

Description

Bug fix

Resolves the TypeScript type error when using the Turbopack configuration example in a next.config.ts file.

The original example showed:

turbopack: (config) => {
  nrExternals(config)
  return config
}

This mirrors webpack's callable interface, but TurbopackOptions is a plain object — not a function — so TypeScript rejects it with:

Type '(config: any) => any' has no properties in common with type 'TurbopackOptions'. Did you mean to call it? ts(2560)

Changes:

  • Renames next.config.jsnext.config.ts with proper types (import type { NextConfig }, typed const, export default)
  • Documents that nrExternals is webpack-specific and does not apply to Turbopack — newrelic is already automatically excluded from bundling in Next.js 15+
  • Shows the correct turbopack: { } object syntax with a comment
  • Removes the deprecated experimental.serverComponentsExternalPackages block (superseded by serverExternalPackages in Next.js 15+)
  • Updates tsconfig.json to moduleResolution: bundler (the correct setting for Next.js projects, replaces deprecated node)

Hybrid agent (OpenTelemetry bridge)

This example now uses the New Relic hybrid agent instead of native Next.js instrumentation. Requires Next.js >= 16 and newrelic >= 14.1.0.

The hybrid agent routes OpenTelemetry SDK signals through the New Relic pipeline, which is the supported path for Next.js 16+. Native agent support for Next.js 14 and 15 is no longer maintained in this example (though not yet deprecated) — users on those versions should refer to the nextjs-legacy example.

Changes:

  • newrelic.js: enables opentelemetry.enabled: true; disables the built-in http, undici, and next instrumentations to prevent duplicate spans when OTel instrumentations are active
  • package.json: pins next to ^16.0.0, upgrades newrelic to ^14.1.0 (minimum for Next.js OTel support)- README.md: adds a version requirement callout and links to nextjs-legacy for users on Next.js < 16

Additional fixes

While validating the example against Next.js 16 / Node.js 24 (latest of each at time of writing):

  • Build hang: guards all require('newrelic') calls behind process.env.NEXT_PHASE !== 'phase-production-build' — the agent was initializing at build time and waiting indefinitely for a connected event, hanging every static generation worker
  • Async params: fixes params.id being undefined in pages and route handlers — in Next.js 15+, params is a Promise and must be awaited (server components) or unwrapped with React.use() (client components)
  • Edit page: after saving a user, redirects to the view page and calls router.refresh() to bust the router cache so the updated name is shown
  • ESM loader flag: replaces deprecated --loader with --import in the start script; removes --import from dev where Turbopack's own ESM hooks conflict with it on Node.js 24
  • Missing dependency: adds react-dom as an explicit dependency
  • Linting: migrates from next lint (removed in Next.js 16) to eslint . with a flat eslint.config.mjs and ESLint 9

Related Issues

Closes #345

@bizob2828

Copy link
Copy Markdown
Member

can you update this to use the hybrid agent? you'll have to disable http, next instrumentation in the agent as well?

@amychisholm03 amychisholm03 changed the title fix: Update nextjs-app-router example for Next.js >=15 and TypeScript compatibility fix: Update nextjs-app-router example for Next.js ^16 and TypeScript compatibility Jun 2, 2026
@amychisholm03 amychisholm03 marked this pull request as ready for review June 2, 2026 17:01
@amychisholm03 amychisholm03 requested a review from bizob2828 June 2, 2026 17:01

@bizob2828 bizob2828 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

one small issue in the README, otherwise this works

Comment thread nextjs/nextjs-app-router/README.md Outdated
@amychisholm03 amychisholm03 requested a review from bizob2828 June 3, 2026 15:33
@amychisholm03 amychisholm03 merged commit 48d3175 into main Jun 3, 2026
8 checks passed
@amychisholm03 amychisholm03 deleted the NR-345/nextjs-turbopack-ts-fix branch June 3, 2026 16:14
@github-project-automation github-project-automation Bot moved this from Needs PR Review to Done: Issues recently completed in Node.js Engineering Board Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done: Issues recently completed

Development

Successfully merging this pull request may close these issues.

New Relic Turbopack Example in Next.js Is Not TypeScript-Compatible: Turbopack Config Requires Object, Not Function

3 participants