Skip to content

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:

shell
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/pathToRegexpError

This 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:

  1. Named parameters for wildcard routes
  2. Strict path segment validation
  3. 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 *.

1. Update Wildcard Routes to New Syntax

For Basic Path Matching

js
// Before (Express 4)
app.get('*', handler);

// After (Express 5)
app.get(/(.*)/, handler);  // Regular expression syntax
// OR
app.get('/*path', handler);  // Named wildcard parameter

With Middleware

js
// Before (Express 4)
app.use('/*', middleware);

// After (Express 5)
app.use(/(.*)/, middleware);  // Regular expression syntax

2. Use Named Parameters as Wildcards

Express official migration guide recommends:

js
// 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:

shell
# Remove lockfile to reset dependencies
rm package-lock.json

# Install stable Express 4
npm install express@4.20.0

Warning 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

  1. 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
  2. Named Parameter Syntax
    /*name explicitly defines wildcard parameters

    • Parameters accessible via req.params.name
    • Follows Express 5 best practices
    • /{*splat} allows root path matching
  3. Downgrading
    Avoids breaking changes until you can properly update route patterns

Comparison of Solutions

SolutionCompatibilityPath AccessExpress 5 Ready
/(.*)/✓ Express 4+req.params[0]
/*path✗ Express 4req.params.path
Express 4✓ LegacyTraditional methods

Final Recommendations

  1. For new projects or deployments: Migrate to Express 5 syntax
  2. For existing large projects: Use regex patterns for easier migration
  3. Avoid npm audit fix --force when using Express 4

Always validate routes after Express updates by:

shell
npm list express  # Verify version
node server.js    # Test locally before deployment

For more details, refer to the official resources: