From 200fe1ebe1076f43ec73e72c287d0d3d22b3dec2 Mon Sep 17 00:00:00 2001 From: marie-fourier Date: Wed, 8 Nov 2023 15:20:43 +0500 Subject: [PATCH] fix dependencies & websocket polyfill --- package.json | 6 +++--- src/node-polyfill.ts | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 84edb12c..61d36f48 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,9 @@ "cross-fetch": "3.1.5", "ethers": "5.7.0", "graphql-ws": "5.14.2", - "prettier": "2.8.8" + "prettier": "2.8.8", + "reflect-metadata": "0.1.13", + "rxjs": "6.6.7" }, "devDependencies": { "@types/node": "18.11.9", @@ -79,8 +81,6 @@ "eslint-config-prettier": "6.11.0", "eslint-plugin-import": "2.20.2", "npm": "9.6.4", - "reflect-metadata": "0.1.13", - "rxjs": "6.6.7", "ts-node": "10.9.1", "typescript": "4.9.5" } diff --git a/src/node-polyfill.ts b/src/node-polyfill.ts index cb558263..72e4002c 100644 --- a/src/node-polyfill.ts +++ b/src/node-polyfill.ts @@ -13,4 +13,7 @@ try { throw new Error('WebSocket not found. Please install `ws` for node.js'); } -(global as any).WebSocket = WebSocketConstructor; +// browsers don't have the `global` and WebSocket is available in window.WebSocket +if (global) { + (global as any).WebSocket = WebSocketConstructor; +}