Skip to content

Commit 6301755

Browse files
committed
fix: 🐛 prevent runtime errors when inlining the dependency into the prod bundle
1 parent d7cb3b6 commit 6301755

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/modules/WebSocketWrapper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ function getWS(): Promise<typeof WS> {
77
if (process.env.ES_TARGET == 'esm') {
88
return import('ws')
99
} else {
10-
// eslint-disable-next-line
11-
return new Promise(resolve => resolve(require('ws')))
10+
return new Promise(resolve => resolve(require('ws'))) // eslint-disable-line
1211
}
1312
}
1413

@@ -47,7 +46,8 @@ export class WebSocketWrapper extends Listener {
4746
this._connectionTimeout.clear()
4847
if (isNodeJS()) {
4948
// NodeJS module
50-
getWS().then(WebSocketClient => {
49+
getWS().then(ws => {
50+
const WebSocketClient = ((ws as any).default as typeof WS) || ws
5151
this.ws = new WebSocketClient(this.url)
5252
this.ws.on('open', () => {
5353
this._status = true
@@ -124,4 +124,4 @@ export class WebSocketWrapper extends Listener {
124124
this._tryReconnect = false
125125
this.ws && this.ws.close()
126126
}
127-
}
127+
}

0 commit comments

Comments
 (0)