#websocket

14 messages · Page 1 of 1 (latest)

fickle quarry
#

generating static routes
01:37:22 ▶ src/pages/404.astro
01:37:22 └─ /404.html (+67ms)
{
ASSETS_PREFIX: undefined,
BASE_URL: '/',
DEV: false,
MODE: 'production',
PROD: true,
PUBLIC_GOOGLE_TAG_MANAGER_ID: '',
PUBLIC_WARGAMING_APPLICATION_ID: '
',
SITE: 'https://blitzkit.app',
SSR: true,
AUTO_PROXY_ORIGIN: '',
_: '/home/runner/work/blitzkit/blitzkit/node_modules/.bin/astro'
}
WebSocket is not defined
Location:
/home/runner/work/blitzkit/blitzkit/node_modules/astro/dist/core/build/pipeline.js:220:15
Stack trace:
at file:///home/runner/work/blitzkit/blitzkit/packages/website-ue/.astro/chunks/metadata.socket_Ds_L7kID.mjs:94784:20
at requestAutoProxyClient (file:///home/runner/work/blitzkit/blitzkit/packages/website-ue/.astro/chunks/metadata.socket_Ds_L7kID.mjs:94783:10)
at file:///home/runner/work/blitzkit/blitzkit/packages/website-ue/.astro/chunks/metadata.socket_Ds_L7kID.mjs:94857:9
at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)
at async generatePages (file:///home/runner/work/blitzkit/blitzkit/node_modules/astro/dist/core/build/generate.js:84:21)

rigid craterBOT
#

Hi @fickle quarry. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The error message WebSocket is not defined during static route generation in Astro indicates that your code (or a dependency) is trying to use the WebSocket API during the build process. However, static builds in Astro run in a Node.js environment, which does not provide browser APIs like WebSocket.

Key points from the knowledge sources:

#
  • Astro's static site generation (SSG) builds all pages at build time in a Node.js environment, where browser-specific APIs (like WebSocket) are not available. If your code or a dependency tries to use WebSocket during this phase, it will fail with this error.
  • To use WebSockets in Astro, you need to use an SSR (server-side rendering) adapter that supports WebSockets, such as those for Deno, Bun, Node, or Cloudflare Workers. These adapters allow you to run code in environments where WebSockets are available at runtime, not during static build time. There are integrations like astro-deno-websocket, astro-bun-websocket, astro-node-websocket, and astro-cloudflare-websocket for this purpose (astro-deno-websocket, astro-bun-websocket, astro-node-websocket, astro-cloudflare-websocket).
  • If you want to use WebSockets, you must not prerender the affected routes. Instead, set export const prerender = false in your .astro files to ensure those routes are rendered on demand (Routing Reference).
  • If you are building a static site, you cannot use WebSockets at build time. You must ensure that any WebSocket-related code only runs in the browser or in a compatible server runtime, not during the static build process.

What you should do:

#
  1. Check your code and dependencies for any usage of WebSocket that might run during the build. Make sure such code is only executed in the browser (e.g., inside if (typeof window !== "undefined") { ... }).
  2. If you need WebSockets, use SSR: Switch to an SSR adapter and set export const prerender = false for the relevant routes.
  3. For static builds, remove or guard WebSocket usage so it does not run during the build process.

If you need more specific guidance, please provide the relevant code snippet or clarify your build target (static vs. SSR).

The knowledge sources do not provide a direct solution for this exact error, but the above steps are derived from the documented behavior of Astro's static and SSR modes and the limitations of browser APIs in Node.js environments (Routing Reference).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@fickle quarry Kapa.ai is still learning and improving, please let me know how I did by reacting below.

fickle quarry
#

@rigid crater uh yes it does. i put it into node and WebSocket is indeed there

rigid craterBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

According to the official Astro documentation, the WebSocket API is not available in the Node.js environment by default. The error WebSocket is not defined during Astro's static build process occurs because browser APIs like WebSocket are not present in the Node.js runtime that Astro uses for static site generation. This is expected behavior, as Astro's build process runs in Node.js, which does not provide browser-specific globals such as window, document, or WebSocket unless you are using a specific runtime or polyfill that provides them.

If you are using a Node.js version or environment where WebSocket appears to be available, it is likely due to a polyfill or a specific package being used, not Node.js itself. The standard Node.js runtime does not include the WebSocket global by default.

Astro's documentation explicitly states that Web APIs are not available in server-rendered code, and you must use client directives or SSR adapters that support such features if you need them. For static builds, you must ensure that any code using browser APIs like WebSocket does not run during the build process, as this will cause errors Upgrade to Astro v3.

If you need to use WebSockets in your Astro project, you should use an SSR adapter and ensure that the relevant code is only executed in the appropriate environment Node Builtins.

#

If you have further details about your Node.js environment or how WebSocket is being made available, please share them. However, based on the official Astro documentation, this is not standard or expected in a typical Node.js environment.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@fickle quarry Kapa.ai is still learning and improving, please let me know how I did by reacting below.

fickle quarry
#

@rigid crater like i said, i am NOT using any polyfill, websocket is available. it's 2025

rigid craterBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Thank you for clarifying. However, based on the knowledge sources provided, there is no information indicating that the Node.js runtime natively provides a global WebSocket object as of the latest documented Astro versions. The official Astro documentation and upgrade guides consistently state that browser APIs like WebSocket are not available in the Node.js environment during static builds, and any usage of such APIs will result in errors unless specifically polyfilled or handled via SSR adapters Upgrade to Astro v3.

If there have been changes to Node.js after the documentation's last update, the knowledge sources do not reflect this. Therefore, I cannot confirm or provide guidance on native WebSocket support in Node.js for Astro projects based on the current documentation. If you are experiencing different behavior in your environment, it is not covered by the official Astro documentation available here.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: