Closed aoneahsan closed 1 week ago
reverted back to "v4.20.0" and it worked.
issue only occurrs when i update express to "v5.0.0"
project depedencies
yes i know this is "next" major release, and current stable version on NPM is "4.20.0", just want to bring this to attention as well, so once on NPM we can the stable version to "5.." it will be fixed before that, thanks :)
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:
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
I think that Express 5.x documentation may have an error:
If you try this you'll trigger the
TypeError: Unexpected ( at 0, expected END: https://git.new/pathToRegexpError
error. Would be worth fixing this to prevent confusion.
@furnivall Yes, 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();
});
Yep, we had to synchronize releases for security reasons, but we were unable to get the docs all updated. Please open PRs with this where you can, we will need all the help we can get.
💰 A bounty of $30.00 has been created by omarsoufiane on BountyHub.
🔗 Claim this bounty by submitting a pull request that solves the issue!
Good luck, and happy coding! 💻
hey @aoneahsan I'd like to resolve this bug, can you please what particularly do I need to do here ?
hey @aoneahsan I'd like to resolve this bug, can you please what particularly do I need to do here ?
@An525ish
@krzysdz here "https://github.com/expressjs/express/issues/5936#issuecomment-2340677058" explained the solution well, please follow it.
let me know if you need any further assistance.
JFR, now
expressApp.use("*", handler())
is not going to work, instead we need to use "own regular expression" like
expressApp.use("/(.*)/", handler())
[DEPLOY-ERROR] - TypeError: Missing parameter name at 1: https://git.new/pathToRegexpError - Firebase Functions Project - Updated to Version 5 - Firebase Deploy Failed
kingsman97:functions ahsan$ nmr deploy:specific
yarn unlink v1.22.22 success Removed linked package "zaions-tool-kit". info You will need to run
yarn install --force
to re-install the package that was linked. ✨ Done in 0.04s. yarn unlink v1.22.22 success Removed linked package "zaions-express-tool-kit". info You will need to runyarn install --force
to re-install the package that was linked. ✨ Done in 0.05s. yarn install v1.22.22 [1/5] 🔍 Validating package.json... [2/5] 🔍 Resolving packages... [3/5] 🚚 Fetching packages... [4/5] 🔗 Linking dependencies... warning " > firebase-functions-test@3.3.0" has unmet peer dependency "jest@>=28.0.0". [5/5] 🔨 Rebuilding all packages... success Saved lockfile. ✨ Done in 4.55s.=== Deploying to 'aoneahsan-learn-p2'...
i deploying functions Running command: npm --prefix "$RESOURCE_DIR" run build
✔ functions: Finished running predeploy script. i functions: preparing codebase default for deployment i functions: ensuring required API cloudfunctions.googleapis.com is enabled... i functions: ensuring required API cloudbuild.googleapis.com is enabled... i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled... ✔ functions: required API cloudfunctions.googleapis.com is enabled ✔ functions: required API cloudbuild.googleapis.com is enabled ✔ artifactregistry: required API artifactregistry.googleapis.com is enabled i functions: Loading and analyzing source code for codebase default to determine what to deploy Serving at port 8526
TypeError: Missing parameter name at 1: https://git.new/pathToRegexpError at name (/Volumes/Personal/01-code-work/firebase-projects/01-zaions/100-ahsan-learn-p1-v1/functions/node_modules/router/node_modules/path-to-regexp/dist/index.js:85:19) at lexer (/Volumes/Personal/01-code-work/firebase-projects/01-zaions/100-ahsan-learn-p1-v1/functions/node_modules/router/node_modules/path-to-regexp/dist/index.js:103:27) at lexer.next ()
at Iter.peek (/Volumes/Personal/01-code-work/firebase-projects/01-zaions/100-ahsan-learn-p1-v1/functions/node_modules/router/node_modules/path-to-regexp/dist/index.js:119:38)
at Iter.tryConsume (/Volumes/Personal/01-code-work/firebase-projects/01-zaions/100-ahsan-learn-p1-v1/functions/node_modules/router/node_modules/path-to-regexp/dist/index.js:125:28)
at Iter.text (/Volumes/Personal/01-code-work/firebase-projects/01-zaions/100-ahsan-learn-p1-v1/functions/node_modules/router/node_modules/path-to-regexp/dist/index.js:141:30)
at consume (/Volumes/Personal/01-code-work/firebase-projects/01-zaions/100-ahsan-learn-p1-v1/functions/node_modules/router/node_modules/path-to-regexp/dist/index.js:166:29)
at parse (/Volumes/Personal/01-code-work/firebase-projects/01-zaions/100-ahsan-learn-p1-v1/functions/node_modules/router/node_modules/path-to-regexp/dist/index.js:197:20)
at /Volumes/Personal/01-code-work/firebase-projects/01-zaions/100-ahsan-learn-p1-v1/functions/node_modules/router/node_modules/path-to-regexp/dist/index.js:308:74
at Array.map ()
Error: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error