Express.js pathToRegexp Missing parameter name Error
Problem Statement
When deploying Express.js applications to cloud platforms like Render, you may encounter an unexpected error when upgrading to Express 5 or running commands like npm audit fix --force. The error typically appears as:
path-to-regexp/dist/index.js:85
throw new TypeError(Missing parameter name at ${i}: ${DEBUG_URL);
^
TypeError: Missing parameter name at 1: https://git.new/pathToRegexpErrorThis error occurs when Express 5's new route parsing rules are applied to your existing route definitions. After upgrading to Express 5, the new router no longer accepts wildcard routes (*) without explicit parameter naming.
Understanding the Cause
Express 5 introduced breaking changes to route path syntax by updating its internal path-to-regexp dependency to v8.0.0. The new version enforces:
- Named parameters for wildcard routes
- Strict path segment validation
- New handling of special characters (
*,:,?,+)
The critical change is that * is no longer treated as a wildcard but as the start of a named parameter (e.g., *splat). Traditional wildcard routes like app.get('*') or app.use('/*') trigger an error due to the missing parameter name after the *.
Recommended Solutions
1. Update Wildcard Routes to New Syntax
For Basic Path Matching
// Before (Express 4)
app.get('*', handler);
// After (Express 5)
app.get(/(.*)/, handler); // Regular expression syntax
// OR
app.get('/*path', handler); // Named wildcard parameterWith Middleware
// Before (Express 4)
app.use('/*', middleware);
// After (Express 5)
app.use(/(.*)/, middleware); // Regular expression syntax2. Use Named Parameters as Wildcards
Express official migration guide recommends:
// Match any path without root
app.get('/*splat', (req, res) => {
// Access captured path: req.params.splat
});
// Match any path including root ('/')
app.get('/{*splat}', (req, res) => {
console.log(req.params.splat); // '' for root path
});3. Downgrade to Express 4 (Temporary Solution)
If immediate migration isn't feasible:
# Remove lockfile to reset dependencies
rm package-lock.json
# Install stable Express 4
npm install express@4.20.0Warning About npm audit
Avoid npm audit fix --force after downgrading. Express 4 might show vulnerabilities but upgrading to Express 5-beta without route updates will reintroduce this error.
How the Solutions Work
Regular Expression Syntax
/(.*)/serves as path-agnostic wildcard that maintains backward compatibility- Captured path segment in:
req.params[0] - Compatible with both Express 4 and 5
- Captured path segment in:
Named Parameter Syntax
/*nameexplicitly defines wildcard parameters- Parameters accessible via
req.params.name - Follows Express 5 best practices
/{*splat}allows root path matching
- Parameters accessible via
Downgrading
Avoids breaking changes until you can properly update route patterns
Comparison of Solutions
| Solution | Compatibility | Path Access | Express 5 Ready |
|---|---|---|---|
/(.*)/ | ✓ Express 4+ | req.params[0] | ✓ |
/*path | ✗ Express 4 | req.params.path | ✓ |
| Express 4 | ✓ Legacy | Traditional methods | ✗ |
Final Recommendations
- For new projects or deployments: Migrate to Express 5 syntax
- For existing large projects: Use regex patterns for easier migration
- Avoid
npm audit fix --forcewhen using Express 4
Always validate routes after Express updates by:
npm list express # Verify version
node server.js # Test locally before deploymentFor more details, refer to the official resources: