Skip to content

FinceptTerminal is a modern finance application offering advanced market analytics, investment research, and economic data tools, designed for interactive exploration and data-driven decision-making in a user-friendly environment.

fix: Resolve WebSocket 'ws' module error with browser shim

tilakpatel227c6164730b14
diff --git a/fincept-terminal-desktop/src/polyfills/ws-shim.ts b/fincept-terminal-desktop/src/polyfills/ws-shim.ts
new file mode 100644
index 000000000..e1cb7b93d
--- /dev/null
+++ b/fincept-terminal-desktop/src/polyfills/ws-shim.ts
@@ -0,0 +1,25 @@
+/**
+ * WebSocket Shim for Browser
+ *
+ * Replaces Node.js 'ws' module with native browser WebSocket
+ * This is needed because many Node.js libraries (ccxt, openai, langchain)
+ * import 'ws' which doesn't work in browsers.
+ */
+
+// Get native browser WebSocket
+const NativeWebSocket = typeof globalThis.WebSocket !== 'undefined'
+ ? globalThis.WebSocket
+ : class MockWebSocket {};
+
+// Export native browser WebSocket as default
+export default NativeWebSocket;
+
+// Also export as named export for compatibility
+export const WebSocket = NativeWebSocket;
+
+// Export WebSocketServer as a no-op (not used in browser)
+export class WebSocketServer {
+ constructor() {
+ console.warn('WebSocketServer is not available in browser environment');
+ }
+}
diff --git a/fincept-terminal-desktop/vite.config.ts b/fincept-terminal-desktop/vite.config.ts
index 36d700c27..588180749 100644
--- a/fincept-terminal-desktop/vite.config.ts
+++ b/fincept-terminal-desktop/vite.config.ts
@@ -17,6 +17,8 @@ export default defineConfig({
'util': 'util',
'url': 'url',
'zlib': 'browserify-zlib',
+ // Replace ws with empty module (browser has native WebSocket)
+ 'ws': path.resolve(__dirname, './src/polyfills/ws-shim.ts'),
},
},
optimizeDeps: {