Express 5 throws 'Missing parameter name' for a route path
TypeError: Missing parameter nameShort answer
Express 5 uses path-to-regexp 8, which needs every parameter and wildcard to have a name and drops the ? suffix and regex. Change '/*' to '/*splat', write optional parts in braces, and replace regex groups with several paths.
Fix it fast
1Find out which cause you have
Find route strings that contain *, ?, parentheses or square brackets. One of them is the path in the error.
grep -rnE "\.(get|post|put|patch|delete|all|use)\(['\"`][^'\"`]*[*?()\[]" src2Match what you see, then jump to its fix
- 1
The error is thrown at startup, for a catch-all routeAn unnamed wildcard such as '*' or '/*'Fix - 2
A route such as /:file.:ext? stops the app at startupAn optional parameter written with ?Fix - 3
A route like /[discussion|page]/:slug fails with an unexpected ( or [ messageRegular expression characters inside the path stringFix
- 1
What does the error look like?
TypeError: Missing parameter nameUnexpected ? or +
Cause 1 of 3
An unnamed wildcard such as '*' or '/*'
1Check
The Express 5 guide says the wildcard must have a name, like parameters do, so /* becomes /*splat. The path-to-regexp README says the error means no name came after the star.
grep -rn "'/\*'\|\"/\*\"" src2Fix
Name the wildcard. To match the root path / as well, wrap it in braces.
app.get('/*splat', handler);
app.get('/{*splat}', handler);3Verify
Start the server and request a deep path; the handler should run.
curl -i http://localhost:3000/a/b/cConfirmed by expressjs.com
Cause 2 of 3
An optional parameter written with ?
1Check
The ? suffix is no longer supported in Express 5, and path-to-regexp now reports a stray ? or + as unexpected.
grep -rn ":[a-zA-Z]*?" src2Fix
Put the optional part in braces.
app.get('/:file{.:ext}', handler);3Verify
Request the path with and without the extension.
curl -i http://localhost:3000/report
curl -i http://localhost:3000/report.pdfConfirmed by expressjs.com
Cause 3 of 3
Regular expression characters inside the path string
1Check
Express 5 does not support regexp characters in path strings. The characters ()[]?+! are reserved and need a backslash if you mean them literally.
grep -rnE "['\"`]/[^'\"`]*[()\[]" src2Fix
Use an array of plain paths.
app.get(['/discussion/:slug', '/page/:slug'], handler);3Verify
Request both paths.
curl -i http://localhost:3000/discussion/hello
curl -i http://localhost:3000/page/helloConfirmed by github.com
How do I stop it coming back?
- Read the routing section of the Express 5 migration guide before upgrading and grep your routes for *, ? and brackets.
- Put route tests in CI that call each path once, so a bad pattern fails before deploy.
- Remember that a wildcard parameter now arrives as an array in req.params.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fixBack end
bcrypt.hash throws 'data and salt arguments required'
Error: data and hash arguments required
The bcrypt package throws this when hash gets null or undefined for the password or for the salt.
4 causes, each with a fixBack end
bcryptjs rejects hash() or compare() with Illegal arguments
Error: Illegal arguments: string, undefined
bcryptjs checks the types of its two arguments and, when either is wrong, throws Illegal arguments followed by the typeof of the first and the second.
3 causes, each with a fixBack end
Express warns 'body-parser deprecated undefined extended'
body-parser deprecated undefined extended
The warning appears because urlencoded() was called without the extended option, which body-parser 1.x has warned about since version 1.4.0.
3 causes, each with a fixBack end
Browser blocks a stylesheet or script: MIME type mismatch with nosniff
The Network tab shows the asset URL answered with Content-Type text/html
With X-Content-Type-Options: nosniff the browser accepts a stylesheet only as text/css and a script only as a JavaScript type.
3 causes, each with a fix