While upgrading a Node.js project from Express v4 to v5, I encountered a confusing error that looked something like this:
At first, I thought it was something deep in the code, but after narrowing it down, the issue came from this familiar catch-all route:
js
// Express v4
app.all("*", (req, res) => {
res.send("Not Found");
});
Turns out, Express v5 introduced a breaking change to how route paths are matched using path-to-regexp.
🧨 The Problem
In Express v5, wildcards must now be named. That means * alone is no longer valid.
Using /* or "*" without a name causes the following internal error:
Missing parameter name at position X
(comes from path-to-regexp used internally by Express)
✅ The Fix
To fix this, you need to name the wildcard route like so:
// Updated for Express v5
app.all("/*splat", (req, res) => {
res.send("Not Found");
});
Or to catch root path / as well:
app.all("/{*splat}", (req, res) => {
res.send("Not Found");
});
📌 What Changed?
In Express v5, the path-to-regexp matching syntax was updated. Wildcards like * must now follow the same naming rule as :param. So use /*splat or /{*splat} instead of plain *.
You can read the official explanation here:
👉 Express v5 Migration Guide
🧠 Lesson Learned
Don’t assume that old catch-all routes will still work in Express 5. If you see weird path matching errors, always check for named wildcards. 💬 Your Turn
If you’ve run into a similar “wait, why is this broken?” moment while upgrading dependencies, share it below! Let's save others the headache.
📌 The Official Reason
“The wildcard * must have a name, matching the behavior of parameters :. Use /splat instead of /.”
https://expressjs.com/en/guide/migrating-5.html#path-syntax
🧠 My Takeaway
Even a small syntax like "*" can lead to a confusing stack trace when libraries upgrade. Always check migration guides for subtle changes like this.
💬 Your Turn
If you’ve run into a similar “wait, why is this broken?” moment while upgrading dependencies, share it below! Let's save others the headache.
Top comments (0)