pladaria / reconnecting-websocket

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

in typescript error #112

Open wildfire810 opened 5 years ago

wildfire810 commented 5 years ago

reconnecting_websocket_1.default is not a constructor

pladaria commented 4 years ago

can you provide a sample code to reproduce this issue?

hanjukim commented 4 years ago

Node v12.16.3 TypeScript v4.0.2

tsconfig.json

{
  "compilerOptions": {
    "target": "es2017",
    "module": "commonjs",
    "allowJs": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "moduleResolution": "node",
    "skipLibCheck": true,
    "strictNullChecks": true,
    "sourceMap": true,
    "baseUrl": "src",
    "sourceRoot": "src",
    "outDir": "dist",
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "dist"
  ]
}

Source

import ReconnectingWebSocket from 'reconnecting-websocket';

console.log(ReconnectingWebSocket); // undefined

@pladaria I am having this problem too.

hanjukim commented 4 years ago
const ReconnectingWebSocket = require('reconnecting-websocket');

require is working btw.

davidzwa commented 3 years ago

I experience the same issue.

houtenbos commented 2 years ago

I fixed it by adding the following option to tsconfig.json in my project: "esModuleInterop": true

stalker8610 commented 1 year ago

In my case "esModuleInterop": true didn't help, but this did:

import ReconnectingWebSocket from 'reconnecting-websocket';
let rws: ReconnectingWebSocket.default;
rws = new (ReconnectingWebSocket as any)(connectionString, [], options);