Skip to content

TypeScript build failing in Node.js-only environment #1561

Closed
@Jomshir98

Description

@Jomshir98

Describe the bug
When building project using this as dependency using typescript with following option (no DOM library):

"compilerOptions": {
    "lib": ["ES2020"], // Or anything really that doesn't include "dom" as one of options
}

The project fails to build with following errors:

node_modules/engine.io-client/build/esm/transport.d.ts:12:15 - error TS2304: Cannot find name 'CloseEvent'.

12     context?: CloseEvent | XMLHttpRequest;
                 ~~~~~~~~~~

node_modules/engine.io-client/build/esm/transport.d.ts:12:28 - error TS2304: Cannot find name 'XMLHttpRequest'.

12     context?: CloseEvent | XMLHttpRequest;
                              ~~~~~~~~~~~~~~

node_modules/engine.io-client/build/esm/transports/polling.d.ts:91:43 - error TS2304: Cannot find name 'XMLHttpRequest'.

91     error: (err: number | Error, context: XMLHttpRequest) => void;
                                             ~~~~~~~~~~~~~~

node_modules/socket.io-client/build/esm/socket.d.ts:14:15 - error TS2304: Cannot find name 'CloseEvent'.

14     context?: CloseEvent | XMLHttpRequest;
                 ~~~~~~~~~~

node_modules/socket.io-client/build/esm/socket.d.ts:14:28 - error TS2304: Cannot find name 'XMLHttpRequest'.

14     context?: CloseEvent | XMLHttpRequest;
                              ~~~~~~~~~~~~~~


Found 5 errors in 3 files.

The same problem also affects engine.io, as seen.

Context
Triaged this issue to version 4.5.0, likely following commit: b862924

The error is because in node-only environment no CloseEvent nor XMLHttpRequest is defined.

Fix suggestion
Similar issues in the past in typings have been fixed by adding following comment to the typings file:

/// <reference lib="dom" />

Temporary workaround for anyone else facing this issue is adding following to TS config:

"compilerOptions": {
    "skipLibCheck": true
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions