Closed bennycode closed 5 years ago
Hi, try setting esModuleInterop
to true
in tsconfig.json
Cloned your repo and updated tsconfig to enable esModuleInterop
. Seems to work as expected:
yarn run v1.12.3
$ yarn dist && node ./dist/WebSocketClient.js
$ tsc
RWS> connect 0
RWS> next delay 4000
RWS> connect { url: 'wss://echo.websocket.org/?time=1543253270059',
protocols: undefined }
RWS> addListeners
RWS> open event
WebSocket is alive!
RWS> accept open
My demo will run when using "esModuleInterop": true
but this introduces a whole set of new problems.
When using esModuleInterop
, then you cannot extend EventEmitter
and namespace-style imports (such as import * as logdown from 'logdown'
) will cause a failure at runtime.
I extended my example to showcase that: https://github.com/bennyn/reconnecting-websocket-node/commit/71c66c1675cb74d09f6ac784998d3e6f7de8012c
This is still an issue at 4.4.0. This project looks abandoned at this point
const ReconnectingWebSocket = require('reconnecting-websocket').default
const ReconnectingWebSocket = require('reconnecting-websocket').default
Not a constructor
That only fixes the types with a TSLint server on, but on runtime it throws the error
solved in latest version
import ReconnectingWebSocket from "reconnecting-websocket"; // ok
however it will fail with require syntax.
var ReconnectingWebSocket = require("reconnecting-websocket"); // error
I am trying to use the
reconnecting-websocket
library in a TypeScript project using Node.js module resolution. Compiling works but when starting the project I am always getting the following error:This is what my
tsconfig.json
looks like:And here is my demo code:
You can also try it yourself by cloning my repository and executing
yarn start
: https://github.com/bennyn/reconnecting-websocket-node