-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TypeError: Missing parameter name at 2: https://git.new/pathToRegexpError #6428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
yes I got also same issue |
I you go to the DEBUG_URL: https://git.new/pathToRegexpError You will see in the README:
I would assume that your route contains PS: |
Yep, as @slagiewka says, please read our migration guide. v5 is a breaking upgrade, and you will need to make some changes to the path syntax you use. If you still think this is a bug after addressing the changes from the guide, please post the route definitions you have and we can take a look. I will leave this open only because I anticipate more folks asking the same question, but will remove the |
I had this problem aswell and can confirm that this is "simply" a breaking change from the V5 update. This problem came up while updating express in an Angular SSR application for me. When setting up SSR, Angular generated exactly the example mentioned above for me. But changing it to Screenshot from the migration section of the express homepage: |
Thanks @wesleytodd and @slagiewka, I confirmed that it is a breaking issue with the new version. As for our usecase we only have this one route, that accepts all requests and send in the app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, '../build', 'index.html'));
}); I opened this issue yesterday because we have to rollback our production and it cost us downtime and delay our app release thinking it's a fault on our recent changes. Funny enough, it's our mistake, we have this untouched code in our RUN npm install express With this, I conclude that this issue is resolved, you guys can close this anytime if no one wants to add more. I just hope no major impact to production servers out there because of silly mistakes like what we did. |
@eru123 same with me I am using express to serve my react build and last 3-year code was working but because I also face same issue after this critical issue, I realize does not matter how much contributor are working on any lib it can have major issue after whole application. |
This is true of all libraries, you have benefited these past years from the stability (and stagnation 😉) of the project. If you are doing something like I will still keep this open for now, because it avoids more duplicate issues, but glad to hear your issue is resolved @eru123! |
In fact, I just pinned this issue so that folks are more likely to see it than to open a new one. |
…y rollback express to v4 and spefcify in CLI that it should use v4 (latest-4 insted of latest), v5 requires additional migration steps expressjs/express#6428
One case that creates this issue in my case is configuring CORS for pre-flight requests. In my case in express 4 the following worked: this._app.options('*', corsSettings); The first parameter here is a wild card which is no longer supported as such (without a name) in express 5. For express 5 the following code works for me: this._app.options(/.*/, corsSettings); Note that in both cases the property private readonly _app: express.Express = express(); Maybe this is of some value for others when upgrading to express version 5. Happy coding! |
Hi, I have 2 routes like this // error in this route
ApiRequestsRouter.get("/:request_id(\\d+)", ApiRequestsController.show);
ApiRequestsRouter.use([isAuth, isBand]);
ApiRequestsRouter.get("/mines", ApiRequestsController.mine); In v4 this works. in v5 I see error about pathtoRegexpError Like the title I can't use // this route is protected by auth
ApiRequestsRouter.get("/mines", ApiRequestsController.mine);
// this is without auth
ApiRequestsRouter.get("/:request_id", ApiRequestsController.show); so how to fix this for express v5.1 ? |
I don't quite understand your problem, but from what I gather, you're having issues with Is that the solution for now? Maybe @blakeembrey can confirm it. |
the problem is I have routes in same level. which handle other things. like the only solution I found on route level is to add prefix to the id route. which is breaking change. |
Not to poke the dead bear, but why were the path changes made? I guess many (at least myself), found the '*' more meaningful and understandable what it applied to, vs. '/{*something}'. I'm sure there was a reason, but is it helping the most people? |
@thetumper this might help: https://blakeembrey.com/posts/2024-09-web-redos/ I think it is linked and called out in both the changelogs and original release announcement. Let us know if there are other places you looked but didn't see it so we can update those with description and links. |
When using Angular SSR and server.get('.',.... to do something with static files, make sure to change '.' into /.[a-zA-Z0-9]+$/ |
If you're trying to use '/**' and it doesn't work, there is a workaround: '/*\w' |
@Adam-Golan |
@krzysdz no it's not, it a metacharecter in regex and it covers all words, exactly like **. https://www.regextutorial.org/regular-expression-metacharacters.php |
@Adam-Golan If you are using regular expressions directly, then yes - In both Express 4 and 5 you can pass a regular expression directly as a path (e.g. According to Express Playground Router in Express 4, the route expression In Express 5, In summary:
I really recommend experimenting with @bjohansebas' Express Playground Router if you want to understand how Express handles routes. |
@krzysdz on that case, if we ever use named capturing group in Regex as path (and not string literal) like this /^\/files\/(?<resource>.*)$/i is it possible to get the |
If you use a named capturing group then it is available as |
Great! I love using Regex all the time, that's a one great thing to have. |
In my case I had a route like in the example '/:file.:ext?' using @expressjs/codemod it was not possible to detect where it was, I was testing starting the server with small groups of files |
@Samuelplim |
For people who use Angular, the upgrade has been done here: angular/angular-cli#29989 |
Environment information
Version: v5.1.0
Platform: Linux 6.8.0-1021-aws 23~22.04.1-Ubuntu SMP Tue Dec 10 16:50:46 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Node.js version: v16.20.2
Any other relevant information: N/A
What steps will reproduce the bug?
# Installing the latest express cause the issue npm install express
then throws error
Temporary Fix
Downgrade to 4.21.2
The text was updated successfully, but these errors were encountered: