Skip to content

TypeScript build failure in @rocket.chat/http-router due to incorrect Hono router method typing (Node 22 / TS 5.x) #37801

@17dhruv

Description

@17dhruv

Description

While building Rocket.Chat locally from source, the build fails in the @rocket.chat/http-router package due to a TypeScript type incompatibility when dynamically accessing Hono router methods using method.toLowerCase().

The issue originates from TypeScript’s stricter type inference (TS 5.x) combined with Hono’s strongly typed router interface, which no longer allows dynamic string indexing without an explicit and safe narrowing.

This results in a TypeScript compile-time error that blocks yarn build, even though the runtime behavior is valid.

The issue is reproducible on a clean clone, and once a small type-safe adjustment is applied, the entire project builds successfully.

Steps to reproduce

  1. Clone Rocket.Chat repository
git clone https://github.com/RocketChat/Rocket.Chat.git
cd Rocket.Chat
  1. Checkout a recent branch (tested on develop)

git checkout develop

  1. Use the required Node.js version
nvm install 22.16.0
nvm use 22.16.0
  1. Install dependencies

yarn install

  1. Run the build

yarn build

  1. Build fails at:

packages/http-router/src/Router.ts:197

Expected behavior

yarn build should complete successfully on a clean setup using the officially required Node.js version.

TypeScript should accept valid dynamic routing logic when using Method enums with Hono.

Actual behavior

TypeScript compilation fails with an error similar to:

` error TS2345: Argument of type 'string' is not assignable to parameter of type 'H<...>'`

The error originates from dynamically accessing the Hono router method:

`   this.innerRouter[method.toLowerCase()]`
Image

This prevents the build from completing.

Server Setup Information

  • Version of Rocket.Chat Server: develop (local build)
  • License Type: N/A (local development)
  • Number of Users: N/A
  • Operating System: Ubuntu (WSL2 on Windows)
  • Deployment Method: Source build
  • Number of Running Instances: 1
  • DB Replicaset Oplog: N/A
  • NodeJS Version: v22.16.0
  • MongoDB Version: N/A (build-time issue)

Server Setup Information

  • Version of Rocket.Chat Server: develop (local build)
  • License Type: N/A (local development)
  • Number of Users: N/A
  • Operating System: Ubuntu (WSL2 on Windows)
  • Deployment Method: Source build
  • Number of Running Instances: 1
  • DB Replicaset Oplog: N/A
  • NodeJS Version: v22.16.0
  • MongoDB Version: N/A (build-time issue)

Additional context

This issue is not related to Sharp, Deno, or MongoDB
It is a pure TypeScript + Hono typing regression

Likely surfaced due to:
Node 22 adoption
TypeScript 5.x stricter index access rules

A small refactor can permanently fix this across all environments
I am happy to open a PR with the validated fix if this approach is acceptable.

Heart of the problem:
A TypeScript type mismatch in packages/http-router/src/Router.ts prevents dynamic access to Hono router methods (this.innerRouter[method.toLowerCase()]), breaking local builds despite correct runtime behavior.

Why it’s important to solve:
This blocks contributors from building Rocket.Chat locally and introduces unnecessary friction in development, onboarding, and CI reliability for a core routing layer.

Relevant logs

<details> <summary>TypeScript build error</summary>
packages/http-router/src/Router.ts:197:63
error TS2345: Argument of type 'string' is not assignable to parameter of type 'H<...>'

Successful build after fix yarn build ✔ webpack compiled successfully ✔ all packages built

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