From 708af7efde3859ab5f94ba2dbc6038bf16723ec8 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Thu, 19 Sep 2024 12:37:16 -0700 Subject: [PATCH] Move env vars to vite config --- electron.vite.config.ts | 4 ++++ frontend/util/wsutil.ts | 13 ++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/electron.vite.config.ts b/electron.vite.config.ts index 2a7ab6fe0..dc5f95daa 100644 --- a/electron.vite.config.ts +++ b/electron.vite.config.ts @@ -26,6 +26,10 @@ export default defineConfig({ "@": "frontend", }, }, + define: { + "process.env.WS_NO_BUFFER_UTIL": "true", + "process.env.WS_NO_UTF_8_VALIDATE": "true", + }, }, preload: { root: ".", diff --git a/frontend/util/wsutil.ts b/frontend/util/wsutil.ts index d6908d388..dcda5ad31 100644 --- a/frontend/util/wsutil.ts +++ b/frontend/util/wsutil.ts @@ -3,13 +3,12 @@ import type { WebSocket as NodeWebSocketType } from "ws"; let NodeWebSocket: typeof NodeWebSocketType = null; if (typeof window === "undefined") { - try { - // Necessary to avoid issues with Rollup: https://github.com/websockets/ws/issues/2057 - process.env.WS_NO_BUFFER_UTIL = "1"; - import("ws").then((ws) => (NodeWebSocket = ws.default)); - } catch (error) { - console.log("Error importing 'ws':", error); - } + // Necessary to avoid issues with Rollup: https://github.com/websockets/ws/issues/2057 + import("ws") + .then((ws) => (NodeWebSocket = ws.default)) + .catch((e) => { + console.log("Error importing 'ws':", e); + }); } type ComboWebSocket = NodeWebSocketType | WebSocket;