vercel / vercel/next.js

middleware matcher should support template literals

Open
#56,398 20 comments 49 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Runtime
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/stefanprobst/issue-next-middleware-matcher

To Reproduce
  1. clone https://github.com/stefanprobst/issue-next-middleware-matcher
  2. pnpm install && pnpm run dev
  3. see error message in console: 'Next.js can't recognize the exported config field in route "/middleware": Unsupported template literal with expressions at "config.matcher[1]".'
Current vs. Expected behavior

i would want to be able to do this:

const locales = ["de", "en"] as const;

export const config = {
  matcher: ["/", `/(${locales.join("|")})/:path*`],
};
Verify canary release
  • I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
  Platform: linux
  Arch: x64
  Version: #26~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jul 13 16:27:29 UTC 2
Binaries:
  Node: 18.18.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.8.0
Relevant Packages:
  next: 13.5.4
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

Middleware / Edge (API routes, runtime)

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the linked reproduction with the documented pnpm commands and confirm the matcher validation error. Trace the middleware config matcher validation that reports unsupported template literals, then inspect existing matcher tests if available. Done means the shown template-literal matcher is accepted without the error and existing matcher validation still passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js, typescript
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.