We have created simple express application with following code
const express = require('express')
const app = express()
const port = 4000
function logErrors(err, req, res, next) {
console.error(err.stack)
next(err)
}
function clientErrorHandler(err, req, res, next) {
if (req.xhr) {
res.status(500).send({ error: 'Something failed!' })
} else {
next(err)
}
}
function errorHandler (err, req, res, next) {
res.status(err.statusCode || 500)
res.json({ message: err.message || "something wrong" })
}
app.get('/', async (req, res) => {
await Promise.reject({"message":"dsfjh", statusCode: 400})
res.status(200).send("asfas")
})
app.get('/[discussion|page]/:slug', async (req, res) => {
throw {statusCode: 400, message: "harish"}
res.status(200).send("asfas")
})
app.use(logErrors)
app.use(clientErrorHandler)
app.use(errorHandler)
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
It is throwing following error
~/express5/node_modules/path-to-regexp/dist/index.js:136
throw new TypeError(`Unexpected ${nextType} at ${index}, expected ${type}: ${DEBUG_URL}`);
^
TypeError: Unexpected [ at 1, expected END: https://git.new/pathToRegexpError
at Iter.consume (~/express5/node_modules/path-to-regexp/dist/index.js:136:15)
at consume (~/express5/node_modules/path-to-regexp/dist/index.js:193:16)
at parse (~/express5/node_modules/path-to-regexp/dist/index.js:197:20)
at ~/express5/node_modules/path-to-regexp/dist/index.js:308:74
at Array.map (<anonymous>)
at pathToRegexp (~/express5/node_modules/path-to-regexp/dist/index.js:308:25)
at Object.match (~/express5/node_modules/path-to-regexp/dist/index.js:278:30)
at matcher (~/express5/node_modules/router/lib/layer.js:83:23)
at new Layer (~/express5/node_modules/router/lib/layer.js:90:62)
at Function.route (~/express5/node_modules/router/index.js:421:17)
We identified that path to regexp node module is broken which is causing this issue.
Node.js v20.10.0 used
We have created simple express application with following code
It is throwing following error
We identified that path to regexp node module is broken which is causing this issue.
Node.js v20.10.0 used