Skip to content

@sentry/nextjs - _middleware.ts inside /pages/api-dir gets sentry-related code in production build #4507

Closed
@klaasman

Description

@klaasman

Package + Version

  • other: sentry/nextjs

Version:

6.17.4

Description

Any _middleware.ts file inside the /pages/api directory receives sentry-related code in the outputted file. This is not the case as soon as you move this _middleware.ts file outside this api directory.

As a result the function runtime throws an error because sentry tries to access the window:

/Volumes/[...]/.next/server/pages/api/_middleware.js:6121
var manualScrollRestoration =  true && 'scrollRestoration' in window.history && !!function() {
                                                              ^

ReferenceError: window is not defined

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions