I just deployed the project on Render, and as instructed, I had to change the backend path from localhost to http(s)://example.onrender.com
, but it keeps giving an error related to pathToRegexp
.
Missing parameter name at 1: https://git.new/pathToRegexpError
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
at name (path-to-regexp/dist/index.js:85:19)
at lexer (path-to-regexp/dist/index.js:103:27)
at lexer.next (<anonymous>)
at Iter.peek (path-to-regexp/dist/index.js:119:38)
at Iter.tryConsume (path-to-regexp/dist/index.js:125:28)
at Iter.text (path-to-regexp/dist/index.js:141:30)
at consume (path-to-regexp/dist/index.js:166:29)
at parse (path-to-regexp/dist/index.js:197:20)
at path-to-regexp/dist/index.js:308:74
at Array.map (<anonymous>)
Node.js v20.15.1
[nodemon] app crashed - waiting for file changes before starting...
Running npm start
gave this error.
I tried using ChatGPT for help, but it’s still not working. I also tried updating my node_modules
and checking the routes, but it’s still not working.
1
I had the same issue and found a way to fix it.
- Delete your current package.json file
- Run
npm install express@latest
(this will install express^4.20.0) and overwrite the current express installation - Run
npm audit
to see the audit logs of your application (you may see some vulnerabilities and a suggestion to upgrade express to 5.0.0, ignore them).
I noticed that I had this problem after installing a new package and I had some vulnerability issues so I ran npm audit fix --force
and this upgraded my express installation to 5.0.0 among other things. This 5.0.0 version is a beta version so it keeps causing this issue you’re having. You have to downgrade it to 4.20.0 which is the latest stable release
If you’re working with an Express application, reinstalling Express worked for me. You most likely installed the Express 5.0 beta version by running npm audit fix --force
to fix vulnerabilities
- Delete
package-lock.json
- Reinstall Express package by running
npm install express
0
The TypeError: Missing parameter name at ${i}
error was reported in issue expressjs/express #5936. It was concluded that the documentation has not been updated since the last release. They suggested the following as a temporary workaround until the update:
Express 5.0.0 uses
router
2.0.0, which usespath-to-regexp
8.0.0 and it brings some breaking changes to path handling.The error that you got is caused by using
:
or*
in one of your paths, which is not followed by parameter name. In Express 5 the wildcard*
means something different than in 4.x. In 4.x it would match anything, but in 5.0 it behaves like:
and is a named parameter.You should check your paths, especially ones with
:
,*
,?
and+
to make sure that they are compatible with the new changes.You can find more details in changelogs and the link shown in the error message:
- https://github.com/pillarjs/router/blob/master/HISTORY.md#200–2024-09-09
- https://github.com/pillarjs/path-to-regexp/releases/tag/v8.0.0
- https://github.com/pillarjs/path-to-regexp?tab=readme-ov-file#missing-parameter-name
Source: expressjs/express #5936, comment from krzysdz
The documentation has not been updated yet.
'(.*)'
was recommended since 5.0.0-beta.1, but won’t work any more in 5.0.0. Now if you want to use your own regular expression, it has to be passed directly:<code>app.get(/(.*)/, (req, res, next) => {console.log(req.path, req.params); // req.params will be { '0': '/the/path' }next();});</code><code>app.get(/(.*)/, (req, res, next) => { console.log(req.path, req.params); // req.params will be { '0': '/the/path' } next(); }); </code>app.get(/(.*)/, (req, res, next) => { console.log(req.path, req.params); // req.params will be { '0': '/the/path' } next(); });
Source: expressjs/express #5936, comment from krzysdz