Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Jomshir98 opened this issue Nov 5, 2022 · 4 comments
Closed

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

Jomshir98 opened this issue Nov 5, 2022 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@Jomshir98
Copy link

Jomshir98 commented Nov 5, 2022

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
}
@Jomshir98 Jomshir98 added the to triage Waiting to be triaged by a member of the team label Nov 5, 2022
@callum-bennett
Copy link

Adding "dom" to the compilerOptions lib array also fixes this issue.

  "compilerOptions": {
    "lib": ["es2020", "dom"],
  },

@Jomshir98
Copy link
Author

Adding "dom" to the compilerOptions lib array also fixes this issue.

  "compilerOptions": {
    "lib": ["es2020", "dom"],
  },

Yes, I literally said in the issue that making Node.js only environment (which means not having DOM) is what causes this. So adding "dom" is not a solution, as it makes TS think the code is to run in a browser, not in Node.js.
This issue is about Node.js-only applications where we want TS to show error whenever someone tries to use something Node doesn't have.

@darrachequesne
Copy link
Member

I could indeed reproduce the issue, let me check.

@darrachequesne
Copy link
Member

This should be fixed in version 4.6.0 (see 4d6d95e).

Have a great day!

@darrachequesne darrachequesne added bug Something isn't working and removed to triage Waiting to be triaged by a member of the team labels Feb 8, 2023
@darrachequesne darrachequesne added this to the 4.6.0 milestone Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants