nextjs - 💡(How to fix) Fix Instrumentation.onRequestError error parameter type does not match the docs [2 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

export function onRequestError( error: { digest: string } & Error, request: { path: string // resource path, e.g. /blog?name=foo method: string // request method. e.g. GET, POST, etc headers: { [key: string]: string | string[] } }, context: { routerKind: 'Pages Router' | 'App Router' // the router type routePath: string // the route file path, e.g. /app/blog/[dynamic] routeType: 'render' | 'route' | 'action' | 'proxy' // the context in which the error occurred renderSource: | 'react-server-components' | 'react-server-components-payload' | 'server-rendering' revalidateReason: 'on-demand' | 'stale' | undefined // undefined is a normal request without revalidation renderType: 'dynamic' | 'dynamic-resume' // 'dynamic-resume' for PPR } ): void | Promise<void>

Fix Action

Fixed

Code Example

> export function onRequestError(
>   error: { digest: string } & Error,
>   request: {
>     path: string // resource path, e.g. /blog?name=foo
>     method: string // request method. e.g. GET, POST, etc
>     headers: { [key: string]: string | string[] }
>   },
>   context: {
>     routerKind: 'Pages Router' | 'App Router' // the router type
>     routePath: string // the route file path, e.g. /app/blog/[dynamic]
>     routeType: 'render' | 'route' | 'action' | 'proxy' // the context in which the error occurred
>     renderSource:
>       | 'react-server-components'
>       | 'react-server-components-payload'
>       | 'server-rendering'
>     revalidateReason: 'on-demand' | 'stale' | undefined // undefined is a normal request without revalidation
>     renderType: 'dynamic' | 'dynamic-resume' // 'dynamic-resume' for PPR
>   }
> ): void | Promise<void>
>

---

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 23.6.0: Mon Jan 19 22:02:22 PST 2026; root:xnu-10063.141.1.710.3~1/RELEASE_X86_64
  Available memory (MB): 32768
  Available CPU cores: 16
Binaries:
  Node: 22.18.0
  npm: 10.9.3
  Yarn: 1.22.22
  pnpm: 11.5.0
Relevant Packages:
  next: 16.3.0-canary.42 // Latest available version is detected (16.3.0-canary.42).
  eslint-config-next: N/A
  react: 19.2.7
  react-dom: 19.2.7
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/sculli-net/instrumentation-types-reproduction

To Reproduce

  1. Clone repo
  2. Install packages pnpm i
  3. Open instrumentation.ts

Current vs. Expected behavior

The code within instrumentation.ts is an exact copy of the sample within the next.js docs. Despite the docs saying the following:

Types:

export function onRequestError(
  error: { digest: string } & Error,
  request: {
    path: string // resource path, e.g. /blog?name=foo
    method: string // request method. e.g. GET, POST, etc
    headers: { [key: string]: string | string[] }
  },
  context: {
    routerKind: 'Pages Router' | 'App Router' // the router type
    routePath: string // the route file path, e.g. /app/blog/[dynamic]
    routeType: 'render' | 'route' | 'action' | 'proxy' // the context in which the error occurred
    renderSource:
      | 'react-server-components'
      | 'react-server-components-payload'
      | 'server-rendering'
    revalidateReason: 'on-demand' | 'stale' | undefined // undefined is a normal request without revalidation
    renderType: 'dynamic' | 'dynamic-resume' // 'dynamic-resume' for PPR
  }
): void | Promise<void>
  • error: The caught error itself (type is always Error), and a digest property which is the unique ID of the error.
  • request: Read-only request information associated with the error.
  • context: The context in which the error occurred. This can be the type of router (App or Pages Router), and/or (Server Components ('render'), Route Handlers ('route'), Server Actions ('action'), or Proxy ('proxy')).

Type of err shows up as unknown, despite the docs describing it as error: { digest: string } & Error. This requires either a cast or a type check to enable this code to pass typescript build checks. <img width="616" height="429" alt="Image" src="https://github.com/user-attachments/assets/f37f6b68-8f44-4df7-9151-212dae30aa42" />

The docs do specify the following:

The error instance might not be the original error instance thrown, as it may be processed by React if encountered during Server Components rendering. If this happens, you can use digest property on an error to identify the actual error type.

Though if a type check is expected then the sample should show something like message: err instanceof Error ? err.message : String(err), otherwise we should modify the Type with the source code to match the expected { digest: string } & Error type.

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 23.6.0: Mon Jan 19 22:02:22 PST 2026; root:xnu-10063.141.1.710.3~1/RELEASE_X86_64
  Available memory (MB): 32768
  Available CPU cores: 16
Binaries:
  Node: 22.18.0
  npm: 10.9.3
  Yarn: 1.22.22
  pnpm: 11.5.0
Relevant Packages:
  next: 16.3.0-canary.42 // Latest available version is detected (16.3.0-canary.42).
  eslint-config-next: N/A
  react: 19.2.7
  react-dom: 19.2.7
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Instrumentation

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

I am using the project/workspace version of typescript.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING