diff --git a/electron.vite.config.ts b/electron.vite.config.ts index 2a7ab6fe..dc5f95da 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 d6908d38..dcda5ad3 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;