Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Express 5 throws 'Missing parameter name' for a route path

ErrorTypeError: Missing parameter name

Short 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.

  • Applies to Express 5, path-to-regexp 8, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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)\(['\"`][^'\"`]*[*?()\[]" src
  2. 2Match what you see, then jump to its fix

    1. 1The error is thrown at startup, for a catch-all routeAn unnamed wildcard such as '*' or '/*'Fix
    2. 2A route such as /:file.:ext? stops the app at startupAn optional parameter written with ?Fix
    3. 3A route like /[discussion|page]/:slug fails with an unexpected ( or [ messageRegular expression characters inside the path stringFix

What does the error look like?

  • TypeError: Missing parameter name
  • Unexpected ? 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 "'/\*'\|\"/\*\"" src

2Fix

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/c

Confirmed by expressjs.com

Did this fix it?

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]*?" src

2Fix

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.pdf

Confirmed by expressjs.com

Did this fix it?

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 "['\"`]/[^'\"`]*[()\[]" src

2Fix

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/hello

Confirmed by github.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.