Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Invalid token at 1: https://git.new/pathToRegexpError

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.

like image 706
user25346990 Avatar asked Dec 02 '25 01:12

user25346990


1 Answers

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 uses path-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:

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

like image 120
rozsazoltan Avatar answered Dec 03 '25 18:12

rozsazoltan