pladaria / reconnecting-websocket

Reconnecting WebSocket. For Web, React Native, cli (Node.js)
MIT License
1.23k stars 198 forks source link

This expression is not constructable #196

Open bennycode opened 1 year ago

bennycode commented 1 year ago

Hello, I am using TS 5.2 and ESM modules ("module": "NodeNext" & "moduleResolution": "Node16"). I have also activated "esModuleInterop": true.

I am using RWS in the following way:

import ReconnectingWebSocket from 'reconnecting-websocket';

// ...

const socket = new ReconnectingWebSocket(this.baseURL, [], options);

However, I am getting this error:

This expression is not constructable. Type 'typeof import("/home/bennycode/dev/bennycode/coinbase-pro-node/node_modules/reconnecting-websocket/dist/reconnecting-websocket")' has no construct signatures.ts(2351)

I can fix the error by writing:

socket = new ReconnectingWebSocket.default(this.baseURL, [], options);

But then my code crashes during execution with:

TypeError: ReconnectingWebSocket.default is not a constructor

How can I properly fix this error? I am currently cheating the compiler with:

const socket = new (ReconnectingWebSocket as any)(this.baseURL, [], options) as ReconnectingWebSocket.default;
knJayden commented 5 months ago

I am still having this issue