Skip to content

/errors/express/missing-parameter-name

Express 5: TypeError: Missing parameter name at index 1: *

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
Express
exit code
1
versions
Express 5.x
os
any

Express 5 upgraded its router to path-to-regexp 8, where every wildcard must have a name. app.get('*', ...) therefore throws TypeError: Missing parameter name at index 1: *; visit https://git.new/pathToRegexpError for info when the route is registered. Use a named wildcard: app.get('/*splat', ...), or app.get('/{*splat}', ...) to also match /.

Reproduce it and test the replacements

bash
npm init -y >/dev/null
npm install --silent --no-audit --no-fund express@5 >/dev/null 2>&1
cat > app.js <<'EOF'
const express = require("express");
for (const p of ["*", "/api/*", "/users/:id?", "/*splat", "/{*splat}", "/users{/:id}"]) {
  try { express().get(p, (req, res) => res.end()); console.log(`ok     ${p}`); }
  catch (e) { console.log(`error  ${p}  ${e.name}: ${e.message}`); }
}
EOF
node app.js

Output

error  *  TypeError: Missing parameter name at index 1: *; visit https://git.new/pathToRegexpError for info
error  /api/*  TypeError: Missing parameter name at index 6: /api/*; visit https://git.new/pathToRegexpError for info
error  /users/:id?  TypeError: Unexpected ? at index 10: /users/:id?; visit https://git.new/pathToRegexpError for info
ok     /*splat
ok     /{*splat}
ok     /users{/:id}

What the named wildcard matches

bash
npm init -y >/dev/null
npm install --silent --no-audit --no-fund express@5 >/dev/null 2>&1
cat > app.js <<'EOF'
const express = require("express");
const app = express();
app.get("/files/*path", (req, res) => res.json(req.params.path));
app.get("/{*rest}", (req, res) => res.json({ fallback: req.path }));
const server = app.listen(4401, "127.0.0.1", async () => {
  for (const u of ["/files/a/b.txt", "/", "/about"]) {
    const r = await fetch(`http://127.0.0.1:4401${u}`);
    console.log(u.padEnd(16), "->", await r.text());
  }
  server.close();
});
EOF
node app.js

Output

/files/a/b.txt   -> ["a","b.txt"]
/                -> {"fallback":"/"}
/about           -> {"fallback":"/about"}

In Express 5 the value of a named wildcard is an array of path segments (["a", "b.txt"]), not a string; join it with / if you need the path.

Express 4 to 5 route syntax

Express 4Express 5
app.get('*')app.get('/{*splat}') or app.use(handler)
app.get('/api/*')app.get('/api/*splat')
app.get('/users/:id?')app.get('/users{/:id}')
app.get('/:file.:ext?')app.get('/:file{.:ext}')
regex characters in strings, such as '/ab+cd'use a RegExp object instead of a string

For a catch-all fallback (single-page app routing, custom 404), middleware without a path is the simplest option and needs no pattern: app.use((req, res) => res.status(404).send('Not found')), placed after all routes.

Sources