Build a Chat App lab: tests 3–6 fail with Cannot access 'WebSocket' before initialization

I am working on the Build a Chat App lab from the Back End Development and APIs v9 curriculum:

https://www.freecodecamp.org/learn/back-end-development-and-apis-v9/lab-chat-app/lab-chat-app

Tests 1 and 2 pass, but tests 3–6 consistently fail.

The Console for test 3 reports:


ReferenceError: Cannot access 'WebSocket' before initialization

Full stack trace:


{
  "stack": "ReferenceError: Cannot access 'WebSocket' before initialization\n    at eval (eval at <anonymous> (file:///workspaces/back-end-development-and-apis/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/tests/test-worker.js:25:29), <anonymous>:4:21)\n    at new Promise (<anonymous>)\n    at eval (eval at <anonymous> (file:///workspaces/back-end-development-and-apis/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/tests/test-worker.js:25:29), <anonymous>:3:13)\n    at eval (eval at <anonymous> (file:///workspaces/back-end-development-and-apis/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/tests/test-worker.js:25:29), <anonymous>:14:3)\n    at MessagePort.<anonymous> (file:///workspaces/back-end-development-and-apis/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/tests/test-worker.js:25:29)\n    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:843:20)\n    at MessagePort.<anonymous> (file:///workspaces/back-end-development-and-apis/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/tests/test-worker.js:25:29)\n    at [nodejs.internal/per_context/messageport:23:28]",
  "message": "Cannot access 'WebSocket' before initialization",
  "type": "Error"
}

My environment:


Node: v24.18.0
npm: 11.16.0
@freecodecamp/freecodecamp-os: 3.5.4
ws: 8.20.0

The server itself is functioning. I independently tested the WebSocket functionality with two clients:


TEST 3: connection successful
TEST 4: PASS
TEST 5: PASS
TEST 6: PASS

The browser UI also successfully connects through the forwarded Codespaces URL and messages work correctly.

The freeCodeCamp test runner, however, produces connections such as:


CONNECTED: Observer
CONNECTED: Alice
CONNECTED: Bob
CONNECTED: Alice
CONNECTED: Bob

but the test 3 Console reports the WebSocket initialization error before the WebSocket test can execute normally.

I have also verified that the local project does not contain the test files; the tests are being dynamically evaluated by:


@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/tests/test-worker.js

Could someone confirm whether this is a known issue with the current Chat App lab/test runner, particularly with Node 24 / freecodecamp-os@3.5.4?

I need to complete this project for a college certificate deadline, so I would appreciate advice on the correct way to proceed if the test runner is malfunctioning.

I can provide screenshots, the project code, or any additional diagnostic output needed.

have you tried pulling the latest version of the repo and see if this keeps happening?

the tests are in the repo, in a markdown file, then transformed into runnable code by the freecodecamp-os engine, in curriculum/locales/english/build-a-chat-app.md

Tengo exactamente el mismo problema. Mi entorno:

  • Node: v24.18.0
  • @freecodecamp/freecodecamp-os: 3.5.4
  • Mismo stack trace exacto (Cannot access 'WebSocket' before initialization, luego __observer.once is not a function, __alice.once is not a function)

Al igual que reportaste, verifiqué mi implementación con un cliente WebSocket independiente (script de Node fuera del test runner) y los 6 user stories funcionan correctamente: conexión, broadcast de join, broadcast de chat (incluido el emisor), y broadcast de left. El problema está claramente en el test-worker, no en la implementación del servidor.

git pull no trajo cambios; sigo en la misma versión de freecodecamp-os. ¿Hay algún workaround mientras se corrige, o alguna forma de marcar el lab como completado manualmente dado que hay evidencia de que la implementación es correcta?

Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.

I am also getting same issue can any one help?

This should be resolved now. Follow the instructions to update.

uh - i have had teh same issue an hour ago - even in a fresh Codespaces?

Please try re-open the server now with freeCodeCamp: Run Course. There should be instructions in the webview to update.

Can confirm that the issue is fixed in new codespoaces, thx

If you are working in codespaces you need to fetch the updates (be sure to safe your work first):

  1. git fetch upstream
  2. git merge upstream/main

Then, relaunch freeCodeCamp: Run Course and the tests must now work :+1: