Skip to content

TypeError: Missing parameter name at 4: https://git.new/pathToRegexpError during Express.js route registration #400

@devhappys

Description

@devhappys

Hello path-to-regexp maintainers,
I'm encountering a TypeError during the startup of my Express.js application that uses path-to-regexp for route parsing. The error occurs during route registration and appears to be triggered by an invalid URL being processed as a route path.
Error Details:

TypeError: Missing parameter name at 4: https://git.new/pathToRegexpError
    at name (F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\src\index.ts:153:13)
    at lexer (F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\src\index.ts:171:21)
    at lexer.next (<anonymous>)
    at Iter.peek (F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\src\index.ts:188:32)
    at Iter.tryConsume (F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\src\index.ts:195:24)
    at Iter.text (F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\src\index.ts:213:26)
    at consume (F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\src\index.ts:285:23)
    at parse (F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\src\index.ts:320:18)
    at F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\src\index.ts:503:40
    at Array.map (<anonymous>)
[[email protected]] injecting env (41) from .env -- tip: ⚙️  load multiple .env files with { path: ['.env.local', '.env'] }
[[email protected]] injecting env (0) from .env -- tip: 🔐 prevent building .env in docker: https://dotenvx.com/prebuild
[[email protected]] injecting env (0) from .env -- tip: 📡 auto-backup env with Radar: https://dotenvx.com/radar
[[email protected]] injecting env (0) from .env -- tip: ⚙️  override existing env vars with { override: true }
[[email protected]] injecting env (0) from .env -- tip: 🛠️  run anywhere with `dotenvx run -- yourcommand`
[2025-08-24 23:16:17] info: 命令存储已选择 {
  raw: undefined,
  selected: 'mongo',
  Symbol(level): 'info',
  Symbol(splat): [ { raw: undefined, selected: 'mongo' } ]
}
[2025-08-24 23:16:18] info: [IPFS] convert-svg-to-png 和 puppeteer 模块加载成功
[2025-08-24 23:16:18] info: [IPFS] convert函数类型:
[2025-08-24 23:16:18] info: [IPFS] executablePath:
[2025-08-24 23:16:18] info: 抽奖存储已选择 {
  raw: 'mongo',
  selected: 'mongo',
  Symbol(level): 'info',
  Symbol(splat): [ { raw: 'mongo', selected: 'mongo' } ]
}
✅ 图片数据服务初始化完成,使用共享的MongoDB连接
[2025-08-24 23:16:18] warn: [SmartHumanCheck] Using default secret for development. Set SMART_HUMAN_CHECK_SECRET in production.
F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\dist\index.js:73
            throw new TypeError(`Missing parameter name at ${i}: ${DEBUG_URL}`);
            ^

TypeError: Missing parameter name at 4: https://git.new/pathToRegexpError
    at name (F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\dist\index.js:73:19)
    at lexer (F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\dist\index.js:91:27)
    at lexer.next (<anonymous>)
    at Iter.peek (F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\dist\index.js:106:38)
    at Iter.tryConsume (F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\dist\index.js:112:28)
    at Iter.text (F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\dist\index.js:128:30)
    at consume (F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\dist\index.js:152:29)
    at parse (F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\dist\index.js:183:20)
    at F:\Repositories\GitHub\Happy-TTS\node_modules\path-to-regexp\dist\index.js:294:74
    at Array.map (<anonymous>)

Node.js v24.3.0

Environment:
OS: Windows 10 (win32 10.0.22631)
Node.js version: v24.3.0
path-to-regexp version: "path-to-regexp": "^8.2.0",
Express.js version: "express": "^5.1.0",
"express-rate-limit": "^7.5.0",
Project Context:
This error occurs in my open-source project: https://github.com/devhappys/Happy-TTS
Analysis:
The error message indicates that path-to-regexp is trying to parse https://git.new/pathToRegexpError as a route path, which is clearly an invalid route path (it's a complete URL rather than a relative path). The error occurs at position 4, which corresponds to the colon in https://.
Questions for the maintainers:
Input Validation: Should path-to-regexp validate that input paths are valid route paths (relative paths starting with /) rather than complete URLs?
Error Handling: Could path-to-regexp provide more descriptive error messages when it encounters invalid input, such as complete URLs or malformed paths?
Debugging: Is there a way to enable debug mode to see which specific route registration is causing this issue?
Potential Workarounds:
I've implemented input validation in my application to ensure all route paths are valid before registration, but it would be helpful to understand if this is expected behavior or if there's a bug in the library.
Reproduction Steps:
Clone the repository: git clone https://github.com/devhappys/Happy-TTS.git
Install dependencies: npm install
Start the application: npm start
The error occurs during startup
Additional Information:
I've already implemented route path validation in my application to prevent this issue, but I'm reporting this to help improve the library's robustness and error handling.
Thank you for your time and consideration. I appreciate any guidance you can provide on this matter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions