You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Public declaration files reference undeclared dependency ws #353
@hono/node-server exposes ws in its public declaration files, but ws is not declared as a dependency.
For example, dist/index.d.mts contains:
import{WebSocket,WebSocketServer}from"ws";
However, ws is currently only a devDependency.
This causes TypeScript consumers to fail compilation with:
TS2307: Cannot find module 'ws' or its corresponding type declarations.
This is reproducible under pnpm / NodeNext module resolution, but the issue is not pnpm-specific — consumers are not expected to install a package's devDependencies.
Since ws is referenced from public .d.ts/.d.mts files, it is effectively part of the package's public type surface and should probably be declared as one of:
dependencies
peerDependencies
optional peer dependency
Otherwise consumers must manually install ws (and sometimes @types/ws) even if they do not use websocket functionality directly.
We don't want to add external libraries, including ws and @types/ws, to dependencies and peerDependencies. So, users should set skipLibCheck:true and install ws and @types/ws manually if they want to use the WebSockets feature.
We left the following description on the README.
To enable this, install ws (and @types/ws) in your project, then create and provide a WebSocketServer as shown in the example below.
Hy @BlankParticle! Do you have any other option for this?
Hey, sorry to hear that you guys are having this issue, I develop with skipLibCheck: true so I never ran into this problem.
But this is a problem that people who are not using websockets are having issues with ws types.
Based on the parts we use in our code this is the minimal types we would need, so we can accept WebSocketServer objects from users without knowing the exact types.
importtype{IncomingMessage}from'node:http'importtype{Duplex}from'node:stream'typeWSReadyState=0|1|2|3;exporttypeWebSocketData=string|ArrayBuffer|Uint8Array|readonlyUint8Array[]exporttypeWebSocketSendOptions={compress?: boolean}exportinterfaceWebSocketLike{protocol: stringreadyState: WSReadyStateclose(code?: number,reason?: string): voidsend(data: string|ArrayBuffer|ArrayBufferView,options?: WebSocketSendOptions): voidon(event: 'message',listener: (data: WebSocketData,isBinary: boolean)=>void): this
on(event: 'close',listener: (code: number,reason: Uint8Array)=>void): this
on(event: 'error',listener: (error: unknown)=>void): this
off(event: 'message',listener: (data: WebSocketData,isBinary: boolean)=>void): this
}exportinterfaceWebSocketServerLike{options: {noServer?: boolean}on(event: 'connection',listener: (ws: WebSocketLike,request: IncomingMessage)=>void): this
on(event: 'headers',listener: (headers: string[])=>void): this
off(event: 'headers',listener: (headers: string[])=>void): this
emit(event: 'connection',ws: WebSocketLike,request: IncomingMessage): booleanhandleUpgrade(request: IncomingMessage,socket: Duplex,head: Buffer,callback: (ws: WebSocketLike)=>void): voidclose(): void}
I have a suggestion: use “subpath exports”, just like Hono itself does. Move everything related to ws into @hono/node-server/ws, and use interface merging to add websocket to Option.
I have a suggestion: use “subpath exports”, just like Hono itself does. Move everything related to ws into @hono/node-server/ws, and use interface merging to add websocket to Option.
I can't imagine how /ws subpath would be used, but I think its better to just duck type the public api we accept instead of trying to make interface merging work given how fiddly it is to make it work properly
I definitely enabled "subpath exports" on hono, but I don't think we need to do the same for @hono/node-server. And the topic is out of scope of this issue, right?
Activity
Venerons commentedon May 14, 2026
Same issue here, typescript compilation fails after a
npm ciheroboy commentedon May 21, 2026
One workaround is to set
skipLibChecktotrueintsconfig.json.yusukebe commentedon May 23, 2026
We don't want to add external libraries, including
wsand@types/ws, to dependencies and peerDependencies. So, users should setskipLibCheck:trueand installwsand@types/wsmanually if they want to use the WebSockets feature.We left the following description on the README.
Hy @BlankParticle! Do you have any other option for this?
BlankParticle commentedon May 23, 2026
Hey, sorry to hear that you guys are having this issue, I develop with
skipLibCheck: trueso I never ran into this problem.But this is a problem that people who are not using websockets are having issues with
wstypes.@yusukebe I think the best way to fix this problem is to not use
wstypes and replace them with same structural types that confront towstypes, so we would be able to use them without public dependency on@types/ws.Basically we need to copy the public facing type of
WebSocketandWebSocketServer(https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/ws/index.d.ts)Based on the parts we use in our code this is the minimal types we would need, so we can accept
WebSocketServerobjects from users without knowing the exact types.I will make the PR if this works
yusukebe commentedon May 23, 2026
@BlankParticle Thanks for the super quick response. Sounds good. Please!
BlankParticle commentedon May 23, 2026
I have made the PR along with a lint rule to prevent this from happening again
#359
we can close #358 as we will not expose
wspublicly anymoreheroboy commentedon May 23, 2026
I have a suggestion: use “subpath exports”, just like Hono itself does. Move everything related to
wsinto@hono/node-server/ws, and use interface merging to add websocket toOption.BlankParticle commentedon May 23, 2026
I can't imagine how
/wssubpath would be used, but I think its better to just duck type the public api we accept instead of trying to make interface merging work given how fiddly it is to make it work properlyyusukebe commentedon May 24, 2026
I definitely enabled "subpath exports" on
hono, but I don't think we need to do the same for@hono/node-server. And the topic is out of scope of this issue, right?