{"record":{"id":"feb04af4f967d492","repo":"dotnet/runtime","slug":"please-install-ws-npm-package-to-enable-networki-feb04a","errorCode":null,"errorMessage":"Please install `ws` npm package to enable networking support.","messagePattern":"Please install `ws` npm package to enable networking support\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/web-socket.ts","lineNumber":499,"sourceCode":"\nfunction resolvedPromise(): Promise<void> | null {\n    // signal that we are finished synchronously\n    // this is optimization, which doesn't allocate and doesn't require to marshal resolve() call to C# side.\n    return null;\n}\n\nfunction rejectedPromise(message: string): Promise<any> | null {\n    const resolved = Promise.reject(new Error(message));\n    return wrapAsCancelable<void>(resolved);\n}\n\nfunction verifyEnvironment() {\n    if (ENVIRONMENT_IS_SHELL) {\n        throw new Error(\"WebSockets are not supported in shell JS engine.\");\n    }\n    if (typeof globalThis.WebSocket !== \"function\") {\n        const message = ENVIRONMENT_IS_NODE\n            ? \"Please install `ws` npm package to enable networking support.\"\n            : \"This browser doesn't support WebSocket API. Please use a modern browser. See also https://learn.microsoft.com/aspnet/core/blazor/supported-platforms\";\n        throw new Error(message);\n    }\n}\n","sourceCodeStart":481,"sourceCodeEnd":504,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/web-socket.ts#L481-L504","documentation":"Thrown by verifyEnvironment when running under Node (ENVIRONMENT_IS_NODE) and globalThis.WebSocket is not a function. Node's stdlib does not provide WebSocket natively in older versions, so the runtime requires the `ws` npm package to be installed and registered before any WebSocket operation.","triggerScenarios":"Calling ClientWebSocket.ConnectAsync (or any WS API) from a .NET WASM app executed under Node, in a project where `ws` is not installed or not loaded before the runtime initializes the global.","commonSituations":"Fresh clone that didn't run npm install for ws; running under an older Node that lacks a built-in WebSocket; bundlers that tree-shake ws out of the global.","solutions":["Install the package: npm install ws (and @types/ws for TS).","Ensure ws is required/imported before the runtime's first WebSocket use so globalThis.WebSocket is set.","Upgrade to a Node version (>=22) that ships a built-in WebSocket global."],"exampleFix":"// before: nothing imported\nconst ws = new WebSocket(url); // globalThis.WebSocket missing\n\n// after\nimport { WebSocket } from 'ws';\nglobalThis.WebSocket = WebSocket as any;\nconst ws = new WebSocket(url);","handlingStrategy":"validation","validationCode":"function ensureWebSocketForNode() {\n    if (typeof globalThis.WebSocket !== \"function\" && typeof require === \"function\") {\n        try { globalThis.WebSocket = require(\"ws\"); }\n        catch { throw new Error(\"Install `ws`: npm install ws\"); }\n    }\n}","typeGuard":"const hasWebSocket = (): boolean => typeof globalThis.WebSocket === \"function\";","tryCatchPattern":null,"preventionTips":["Add `ws` to package.json dependencies when running under Node.","Import and assign globalThis.WebSocket before starting the runtime.","Use Node >= 22 for a built-in WebSocket global."],"tags":["websocket","node","environment","network","dependencies"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}