graphql-request icon indicating copy to clipboard operation
graphql-request copied to clipboard

4.3/5.0 broken on Node.js with Typescript: WebSocket is not defined

Open Qix- opened this issue 3 years ago • 2 comments

WebSocket functionality was introduced in #330 but assumed that WebSocket was available everywhere. This is only the case in the DOM - Node does not have WebSocket available in the global scope. This makes typescript compilation fail in all cases.

Reference comment (cc @SimenB): https://github.com/prisma-labs/graphql-request/pull/330#issuecomment-1239246563

Qix- avatar Sep 07 '22 11:09 Qix-

Looks like this breaking change was actually introduced in a minor bump 4.3.

Qix- avatar Sep 07 '22 11:09 Qix-

I have the same problem!

node_modules/graphql-request/dist/graphql-ws.d.ts:19:25 - error TS2304: Cannot find name 'WebSocket'.

19 constructor(socket: WebSocket, { onInit, onAcknowledged, onPing, onPong }: SocketHandler); ~~~~~~~~~

Found 1 error(s).

I fixed for now with "skipLibCheck": true In tsconfig.json

lcanavesio avatar Sep 08 '22 12:09 lcanavesio

same Issue here node 16 "graphql-request": "^5.0.0",

mhdalmajid avatar Nov 01 '22 03:11 mhdalmajid

Yes, this is a problem. We need to be able to use "graphql-request": "^5.0.0" in nodejs without having to include DOM in the ts.config libs

fedegant avatar Nov 17 '22 14:11 fedegant

"skipLibCheck": true helped, even though it's not a good way to fix things.

irondsd avatar Nov 27 '22 21:11 irondsd

This is still an issue. Bump

ckifer avatar Sep 15 '23 17:09 ckifer