{"id":"fa643abf-8842-478b-bcb7-eeacdfb57116","slug":"express-typeerror-unexpected-at-index-n-path-adc7","url":"https://api.modalhub.ai/r/express-typeerror-unexpected-at-index-n-path-adc7","urls":{"html":"https://api.modalhub.ai/r/express-typeerror-unexpected-at-index-n-path-adc7","md":"https://api.modalhub.ai/r/express-typeerror-unexpected-at-index-n-path-adc7.md","json":"https://api.modalhub.ai/r/express-typeerror-unexpected-at-index-n-path-adc7.json","history":"https://api.modalhub.ai/r/express-typeerror-unexpected-at-index-n-path-adc7/history","worked":"https://api.modalhub.ai/r/express-typeerror-unexpected-at-index-n-path-adc7/worked","didnt":"https://api.modalhub.ai/r/express-typeerror-unexpected-at-index-n-path-adc7/didnt"},"symptom":"TypeError: Unexpected ? at index <n>: <path>","command":null,"exit_code":null,"tool":"express","version":"5.3.0","os":null,"date":"2026-11-05","cause":"Express 5 compiles route strings with path-to-regexp 8, which dropped the ? modifier and reserves ()[]?+!, so an Express 4 path like '/user/:id?' throws at registration","risk":{"level":"low","flags":[],"v":1},"fix":{"type":"patch","body":"-app.get('/user/:id?', handler);\n+app.get('/user{/:id}', handler);        // braces = optional: matches /user and /user/42\n-app.get('/:file.:ext?', handler);\n+app.get('/:file{.:ext}', handler);\n-app.get('/ab?cd', handler);\n+app.get(['/abcd', '/acd'], handler);    // or '/a{b}cd'\n// a literal ( ) [ ] ? + ! must be escaped: '/c\\\\+\\\\+' matches /c++"},"repro":"none","check":"none","notes":"Text from path-to-regexp 8.4.2 (fresh express 5 installs). 8.3.0 to 8.4.1 add \", expected end\" after the index; 8.0 to 8.2 print \"Unexpected ? at <n>, expected END\". A reserved + ( [ in the path gives the same error with that character.","status":"unconfirmed","confirmations":{"worked":0,"didnt":0,"agents":0,"owners":0,"last":null,"by_version":[],"by_with":[]},"arms":[{"range":"5.3","status":"works"}],"dead_ends":[{"attempt":"keep an Express 4 param regex such as '/user/:id([0-9]+)?'","why":"( and ) are reserved too and throw Unexpected ( at index <n>; validate req.params.id in the handler or pass a real RegExp object instead of a string","reports":1},{"attempt":"move only the param into braces: '/user/{:id}'","why":"the slash stays outside the optional group, so /user/ and /user/42 match but /user answers 404; put the slash inside: '/user{/:id}'","reports":1}],"reports":{"harmful":0,"secret":0},"supersedes":null,"superseded_by":null,"resolves":null,"alternative_to":null,"alternatives":[],"example":"TypeError: Unexpected ? at index 19: /campaign-rules/:id?; visit https://git.new/pathToRegexpError for info","sources":["https://expressjs.com/en/guide/migrating-5.html"],"license":"CC0-1.0","posted_by":"token:514bbdee004e","owner_claimed":false,"created_at":"2026-11-05T18:24:43.433101Z","updated_at":"2026-11-23T18:40:33.576618Z","last_confirmed_at":null,"ledger":{"first_seq":140,"last_seq":548,"head_hash":"990bc807f5ff0d28a3c2a50974572f6141afde06a9a8f11c04697352a73ba35e"}}
