fix: Add helpful error messages for invalid wildcard routes in Express v5#6666
Closed
Abdel-Monaam-Aouini wants to merge 1 commit intoexpressjs:masterfrom
Closed
fix: Add helpful error messages for invalid wildcard routes in Express v5#6666Abdel-Monaam-Aouini wants to merge 1 commit intoexpressjs:masterfrom
Abdel-Monaam-Aouini wants to merge 1 commit intoexpressjs:masterfrom
Conversation
bjohansebas
requested changes
Jul 29, 2025
Member
bjohansebas
left a comment
There was a problem hiding this comment.
-1 on doing this here. We know the error message can be improved, but that would be the responsibility of path-to-regexp, not Express. Also, the message is already being improved in pillarjs/path-to-regexp#363 maybe that resolves part of the issue.
Contributor
|
@bjohansebas I agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description
🎯 Problem
Express v5 introduced stricter path parsing that requires wildcard routes to have named parameters. Previously valid syntax like
app.all('*')now throws crypticpath-to-regexperrors:This creates a poor developer experience when migrating to Express v5, as users get unclear error messages without guidance on how to fix their code.
✅ Solution
This PR enhances Express to catch
path-to-regexperrors related to missing parameter names and provide clear, actionable error messages that guide developers to the correct Express v5 syntax.Before:
After:
🔧 Changes Made
app.route()error handling - Catches path-to-regexp errors and provides helpful messages for wildcard syntax issuesapp.use()error handling - Similar improvements for middleware path validation*,/*,/*/something) while preserving valid syntax (/*splat)📋 Error Message Features
/*splatinstead of*or/*INVALID_WILDCARD_ROUTE,INVALID_WILDCARD_PATH)originalErrorproperty🧪 Testing
app.all()andapp.use()🎁 Benefits
📚 Related Issues
Fixes the wildcard route error issue described in multiple community reports and Stack Overflow questions regarding Express v5 migration difficulties.
Note: This enhancement only improves error messaging - it doesn't change Express v5's requirement for named wildcard parameters, which is the intended behavior per the migration guide.