WebSocket.Server is not a constructor

See original GitHub issue

content is same with title.

I used ‘ws’ module in electron main process not browser.

It work on local environment, but occur error with message ‘WebSocket.Server is not a constructor’ when packaging.

I’m tried to solve this with add external: ['WebSocket', 'WebSocketServer'] in webpack.config.js. but It didn’t work.

anyone who can solve this problem. please, tell me how to solve.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

45reactions
lpincacommented, Oct 16, 2021

There is no ws.Server in the ESM version, use import { WebSocketServer } from 'ws' instead.

8reactions
meoyawncommented, Oct 12, 2021

I’m getting this with ESM:

package.json:

{
  "type": "module",
  "dependencies": {
    "ws": "^8.2.3"
  }
}
import ws from 'ws';

new ws.Server({ port: 8080 });
TypeError: ws.Server is not a constructor
Read more comments on GitHub >

github_iconTop Results From Across the Web

issue in understandind `WebSocketServer` is not a class
It's .Server , not .server . Here's an example: const WebSocket = require('ws'); const wss = new WebSocket.Server({ port: 8080 }).
Read more >
WebSocket is not a constructor - Bugzilla@Mozilla
Please note: I am having Python issues with the WebSocket test server on my computer, so I haven't been able to run all...
Read more >
[NodeJS] TypeError: WebSocket.Server is not a constructor
WS 버전문제.
Read more >
websocket server is not a constructor #528 - Issuehunt
websocket server is not a constructor #528 ... with the following code: const WebSocketServer = require('ws').Server; this.serverPort = 8081; const wss = new ......
Read more >
ws.websocket server is not a constructor - 掘金
ws.websocket server is not a constructor技术、学习、经验文章掘金开发者社区搜索结果。掘金是一个帮助开发者成长的社区,ws.websocket server is not a constructor ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found