peers / peerjs-server

Server for PeerJS

Home Page:https://peerjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: (0 , $cl6Iw$ws.WebSocketServer) is not a constructor

antonio-couto opened this issue · comments

I'm having an issue:

  • I get the error 'TypeError: (0 , $cl6Iw$ws.WebSocketServer) is not a constructor' on a simple project.
    what I am doing wrong please.

  • Version 1.0.0.0

  • Nodejs version v16.16.0

  • Platform: Windows 10 Home

  • I put the code and tsconfig.json file below.

code:

import { PeerServer} from 'peer';
const peerServer = PeerServer({
	port: 9000,
});

tsconfig.json

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  },
  "files": [
    "peer-test.ts"
  ]
}

trace

PS D:\Source\gitlab\voxage\nodejs\screen-peer> node .\peer-test.js
D:\Source\gitlab\voxage\nodejs\screen-peer\node_modules\peer\dist\index.cjs:273
        this.socketServer = config.createWebSocketServer ? config.createWebSocketServer(options) : new (0, $cl6Iw$ws.WebSocketServer)(options);
                                                                                                   ^

TypeError: (0 , $cl6Iw$ws.WebSocketServer) is not a constructor
    at new $e9ffe6de55430dbc$export$f47674b57e51ee3b (D:\Source\gitlab\voxage\nodejs\screen-peer\node_modules\peer\dist\index.cjs:273:100)     
    at $516a786dc008ff17$export$99152e8d49ca4e7d (D:\Source\gitlab\voxage\nodejs\screen-peer\node_modules\peer\dist\index.cjs:522:17)
    at Function.<anonymous> (D:\Source\gitlab\voxage\nodejs\screen-peer\node_modules\peer\dist\index.cjs:560:55)
    at Function.emit (node:events:539:35)
    at Function.<anonymous> (D:\Source\gitlab\voxage\nodejs\screen-peer\node_modules\express\lib\application.js:245:8)
    at Array.forEach (<anonymous>)
    at Function.use (D:\Source\gitlab\voxage\nodejs\screen-peer\node_modules\express\lib\application.js:224:7)
    at $123f4982a51872b4$export$f99d31af51f48b1e (D:\Source\gitlab\voxage\nodejs\screen-peer\node_modules\peer\dist\index.cjs:583:9)
    at Object.<anonymous> (D:\Source\gitlab\voxage\nodejs\screen-peer\peer-test.js:4:42)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    

I'm having this same issue

Thanks for the report. I can’t reproduce this on my machine.

Maybe:

  • remove the lock file and install the npm packages again
  • update Node (v16 should be fine, but 16.16.0 is a year old by now)
  • make sure Windows is up to date

Now I am using nodejs v20.3.0 and I removed modules and the lock file.
Everything is working now.
thanks a lot.