Skip to content

WebSocket type is resolved to any using moduleResolution: "bundler" and ESM #258

@adjsky

Description

@adjsky

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.17.0

Plugin version

8.0.0

Node.js version

16.20.0

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

Pop!_OS 22.04

Description

image

The problem is in the d.ts file. The WebSocket is imported as import * as WebSocket from 'ws', but ws has 2 different d.ts files: the regular one and .mts one, the regular one has a single export export = WebSocket, but the .mts one exports functions, types and the WebSocket itself, resulting in type WebSocket = /*unresolved*/ any.
I haven't seen this problem using "moduleResolution": "node".

Just by changing import * as WebSocket from 'ws' to import WebSocket from 'ws' the problem resolves. If that's okay i can PR fixes.

Steps to Reproduce

  1. Clone repository
  2. Run pnpm install
  3. See no error at line 10 in index.ts
  4. Change moduleResolution to node in tsconfig.json
  5. See an error at line 10 in index.ts
  6. Change moduleResolution to bundler in tsconfig.json
  7. Change import * as WebSocket from 'ws' to import WebSocket from 'ws' in the d.ts file
  8. See an error at line 10 in index.ts

Expected Behavior

The WebSocket type doesn't resolve to /*unresolved*/ any using ESM and moduleResolution: "bundler".

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