Skip to content

[🐛 Bug]: middleware crashes if sentry installed under src directory #420

Closed
@Enalmada

Description

@Enalmada

next-on-pages environment related information

Happens when deploying to preview but also can be reproduced locally:

System:
Platform: linux
Arch: x64
Version: #1 SMP Fri Jan 27 02:56:13 UTC 2023
CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
Memory: 16 GB
Shell: /bin/bash
Binaries:
Node: 18.16.0
Bun: N/A
pnpm: 8.6.9
Yarn: 1.22.19
npm: 9.8.1
Package Manager Used: pnpm
Relevant Packages:
@cloudflare/next-on-pages: 1.5.0
vercel: 31.2.2
next: 13.4.14-canary.0

Description

When using middleware with an array matcher: ['/blog'] pages immediately crashes with

[mf:inf] HEAD /_next/data/1oj9J4jAV41enV60HBD1V/en/blog.json 500 Internal Server Error (4ms)
TypeError: edgeFunction.default is not a function
    at runOrFetchBuildOutputItem (fh03bwcwbs.js:731:42)
    at async RoutesMatcher.runRouteMiddleware (fh03bwcwbs.js:1006:18)
    at async RoutesMatcher.checkRoute (fh03bwcwbs.js:1127:21)
    at async RoutesMatcher.checkPhase (fh03bwcwbs.js:1169:22)
    at async RoutesMatcher.run (fh03bwcwbs.js:1203:20)
    at async findMatch (fh03bwcwbs.js:1221:18)
    at async handleRequest (fh03bwcwbs.js:1217:17)
    at async jsonError (fh03bwcwbs.js:1363:12) {
  stack: TypeError: edgeFunction.default is not a function
…7)
    at async jsonError (fh03bwcwbs.js:1363:12),
  message: edgeFunction.default is not a function
}

This is valid syntax according to https://nextjs.org/docs/app/building-your-application/routing/middleware#matching-paths

Changing to single string like matcher: '/blog' works fine.

I was trying to deploy

matcher: ['/', '/((?!_next|favicon.ico|api|.*\\.).*)', '/api/login', '/api/logout']

was able to work around it by doing something like this but

matcher: '/$|/((?!_next|favicon\\.ico|api|.*\\..*).*))$|/api/login$|/api/logout$',

Reproduction

Create a middleware file with an matcher containing an array and deploy to next-on-pages:

import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
 
export function middleware(request: NextRequest) {
  return NextResponse.next();
}
 
export const config = {
  matcher: ['/about']
}

Note immediate 500 error. Change to matcher: '/about' and redeploy and everything will work fine.

Pages Deployment Method

Pages CI (GitHub/GitLab integration)

Pages Deployment ID

https://37487ae9.t3-challenge.pages.dev

Additional Information

If you are running minified, the error is:

TypeError: (intermediate value).default is not a function
    at k (xxpe9e4ms1j.js:363:55)
    at async w.runRouteMiddleware (xxpe9e4ms1j.js:515:13)
    at async w.checkRoute (xxpe9e4ms1j.js:554:69)
    at async w.checkPhase (xxpe9e4ms1j.js:579:15)
    at async w.run (xxpe9e4ms1j.js:603:13)
    at async G (xxpe9e4ms1j.js:612:10)
    at async z (xxpe9e4ms1j.js:608:50)
    at async jsonError (xxpe9e4ms1j.js:701:12) {
  stack: TypeError: (intermediate value).default is not a f…0)
    at async jsonError (xxpe9e4ms1j.js:701:12),
  message: (intermediate value).default is not a function
}

Would you like to help?

  • Would you like to help fixing this bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    app routerThis issue is related to the App routerblocked by externalThis can't be currently solved because of external factors (Vercel/Next, Pages, etc...)bugSomething isn't workingpages routerThis issue is related to the Pages router

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions