TypeError: Missing parameter name at 2: https://git.new/pathToRegexpError #6723
-
Environment informationVersion: 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 TypeError: Missing parameter name at 2: https://git.new/pathToRegexpError
at name (/var/www/<project>/node_modules/path-to-regexp/dist/index.js:73:19)
at lexer (/var/www/<project>/node_modules/path-to-regexp/dist/index.js:91:27)
at lexer.next (<anonymous>)
at Iter.peek (/var/www/<project>/node_modules/path-to-regexp/dist/index.js:106:38)
at Iter.tryConsume (/var/www/<project>/node_modules/path-to-regexp/dist/index.js:112:28)
at Iter.text (/var/www/<project>/node_modules/path-to-regexp/dist/index.js:128:30)
at consume (/var/www/<project>/node_modules/path-to-regexp/dist/index.js:152:29)
at parse (/var/www/<project>/node_modules/path-to-regexp/dist/index.js:183:20)
at /var/www/<project>/node_modules/path-to-regexp/dist/index.js:294:74
at Array.map (<anonymous>)
/var/www/<project>/node_modules/path-to-regexp/dist/index.js:73
throw new TypeError(`Missing parameter name at ${i}: ${DEBUG_URL}`); Temporary FixDowngrade to 4.21.2 npm install [email protected] |
Beta Was this translation helpful? Give feedback.
Replies: 35 comments
-
yes I got also same issue |
Beta Was this translation helpful? Give feedback.
-
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: |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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: |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
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! |
Beta Was this translation helpful? Give feedback.
-
In fact, I just pinned this issue so that folks are more likely to see it than to open a new one. |
Beta Was this translation helpful? Give feedback.
-
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! |
Beta Was this translation helpful? Give feedback.
-
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 ? |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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? |
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
When using Angular SSR and server.get('.',.... to do something with static files, make sure to change '.' into /.[a-zA-Z0-9]+$/ |
Beta Was this translation helpful? Give feedback.
-
If you use a named capturing group then it is available as |
Beta Was this translation helpful? Give feedback.
-
Great! I love using Regex all the time, that's a one great thing to have. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
@Samuelplim |
Beta Was this translation helpful? Give feedback.
-
For people who use Angular, the upgrade has been done here: angular/angular-cli#29989 |
Beta Was this translation helpful? Give feedback.
-
Go back to previous version this will fix the error |
Beta Was this translation helpful? Give feedback.
-
Hey everyone, I had the same issue, and I worked around it using a regex: Not sure if this will solve your problem too, but it worked for me! |
Beta Was this translation helpful? Give feedback.
-
I had the same issue upgrading to |
Beta Was this translation helpful? Give feedback.
-
hey @Kaike-R @Deni8dev Changing the route to |
Beta Was this translation helpful? Give feedback.
-
@bjohansebas I tested it here, and it worked for me too! I haven’t gone deep into the discussion, but I noticed there are three workarounds for this problem. Among these—{/{splat}},{ /./}, and {'/*\w'} —which one is the most recommended? |
Beta Was this translation helpful? Give feedback.
-
I have been trying to fix this problem for three to four hours and after seeing this post, I got the temporary fix and got the job done for now. |
Beta Was this translation helpful? Give feedback.
-
man thats freaking helpful , i was seacrhing for this from hours i added '/.*/' it added undeined like my fetchURl + undeined + route , so i just set the fecthing of data without fetch url. I was stuck to this for hours man |
Beta Was this translation helpful? Give feedback.
-
still issue for me today ![]() |
Beta Was this translation helpful? Give feedback.
-
const _dirname = path.resolve();
app.use(express.static(path.join(_dirname , "frontend/dist")))
app.get('/*w', async(req , res) => {
res.sendFile(path.resolve(_dirname , "frontend" , "dist" , "index.html"));
})
… Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Please check the migration guide, it shows how routes should be set up. We know that not all functionalities are available yet, due to direct regex support, but it is in the process of being added (see pillarjs/path-to-regexp#379, pillarjs/path-to-regexp#380). Please only report when a route no longer works because the change was not documented. |
Beta Was this translation helpful? Give feedback.
Please check the migration guide, it shows how routes should be set up. We know that not all functionalities are available yet, due to direct regex support, but it is in the process of being added (see pillarjs/path-to-regexp#379, pillarjs/path-to-regexp#380). Please only report when a route no longer works because the change was not documented.