Thanks to visit codestin.com
Credit goes to github.com

Skip to content

When I set matcher: [""] to an empty array in middleware.ts. The development server crashed #57388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
masakinihirota opened this issue Oct 25, 2023 · 3 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js. stale The issue has not seen recent activity.

Comments

@masakinihirota
Copy link

Link to the code that reproduces this issue

https://github.com/masakinihirota/middleware-app

To Reproduce

Setting the matcher property of a middleware to an empty array cause the error message "Invalid middleware found" to be displayed and the development server to crash.

import { NextRequest, NextResponse } from "next/server";

export function middleware(request: NextRequest) {
  if (request.nextUrl.pathname === "/about") {
    return NextResponse.redirect(new URL("/redirected", request.url));
  }
  if (request.nextUrl.pathname === "/another") {
    return NextResponse.rewrite(new URL("/rewrite", request.url));
  }
  return NextResponse.next();
}

export const config = {
  matcher: [""],
  //       ^^^^
};


``

# step by step
[example]
https://github.com/vercel/next.js/tree/canary/examples/middleware

```terminal
pnpm create next-app --example middleware middleware-app
cd middleware-app
pnpm run dev

matcher: ['/about/:path*', '/another/:path*'],
↓ changed
matcher: [''],

`source` is missing for route {"source":""}


Error: Invalid middleware found

Current vs. Expected behavior

Avoid crashing the development server

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
Binaries:
  Node: 18.17.1
  npm: N/A
  Yarn: N/A
  pnpm: 8.7.1
Relevant Packages:
  next: 13.5.6
  eslint-config-next: 12.2.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 4.7.4
Next.js Config:
  output: N/A

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

Not sure, Middleware / Edge (API routes, runtime)

Additional context

No response

@masakinihirota masakinihirota added the bug Issue was opened via the bug report template. label Oct 25, 2023
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label Oct 25, 2023
@masakinihirota
Copy link
Author

middleware.ts config

OK

export const config = {};

export const config = {
matcher: [],
};

export const config = {
matcher: ["/"],
};

No Good

export const config = {
matcher: [""],
};

@nextjs-bot
Copy link
Collaborator

This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.

@nextjs-bot nextjs-bot added the stale The issue has not seen recent activity. label Apr 22, 2025
@nextjs-bot
Copy link
Collaborator

This issue has been automatically closed due to two years of inactivity. If you’re still experiencing a similar problem or have additional details to share, please open a new issue following our current issue template. Your updated report helps us investigate and address concerns more efficiently. Thank you for your understanding!

@nextjs-bot nextjs-bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js. stale The issue has not seen recent activity.
Projects
None yet
Development

No branches or pull requests

2 participants