Tell us what’s happening:
Hello! I am working on the new Build a Chat App lab for the Backend Development and APIs certification.
My code successfully passes all tests locally using an independent client script, and all user stories (connections, join broadcasts, chat broadcasts, and leaves) work as expected. However, when running the tests inside the freeCodeCamp test runner, I am still running into the automated test-worker errors:
ReferenceError: Cannot access ‘WebSocket’ before initialization
TypeError: __observer.once is not a function
My Environment:
Working locally in VS Code
Node version: v24.18.0
I ran git pull and it returned “Already up to date”, but the error persists even after restarting the server and clearing caches.
Since staff mentioned a fix was deployed, what steps do I need to take in a local VS Code / container environment to pull down or force-update the test runner worker script so these tests can register as passed?
(Running locally on localhost)
Your code so far
import http from "http";
import fs from "fs";
import path from "path";
import { WebSocketServer, WebSocket } from "ws";
const PORT = 3001;
const server = http.createServer((req, res) => {
const parsedUrl = new URL(req.url, `http://${req.headers.host || "localhost"}`);
let filePath = path.join(
process.cwd(),
"public",
parsedUrl.pathname === "/" ? "index.html" : parsedUrl.pathname
);
fs.readFile(filePath, (err, data) => {
if (err) {
res.writeHead(404, { "Content-Type": "text/html" });
res.end("404 Not Found");
return;
}
let contentType = "text/html";
if (filePath.endsWith(".js")) contentType = "application/javascript";
if (filePath.endsWith(".css")) contentType = "text/css";
res.writeHead(200, { "Content-Type": contentType });
res.end(data);
});
});
const wss = new WebSocketServer({ server });
wss.on("connection", (socket, req) => {
const urlParams = new URL(req.url, `http://${req.headers.host || "localhost"}`);
const username = urlParams.searchParams.get("username") || "Anonymous";
// Broadcast system message that a user joined
const joinPayload = JSON.stringify({
type: "system",
text: `${username} joined`,
});
wss.clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN) {
client.send(joinPayload);
}
});
// Handle incoming chat messages safely
socket.on("message", (data) => {
try {
const parsed = JSON.parse(data.toString());
const chatPayload = JSON.stringify({
type: "chat",
username: parsed.username || username,
text: parsed.text || data.toString(),
});
wss.clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN) {
client.send(chatPayload);
}
});
} catch (e) {
// If raw text is sent instead of JSON, broadcast it cleanly anyway
const fallbackPayload = JSON.stringify({
type: "chat",
username: username,
text: data.toString(),
});
wss.clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN) {
client.send(fallbackPayload);
}
});
}
});
// Handle client disconnection
socket.on("close", () => {
const leavePayload = JSON.stringify({
type: "system",
text: `${username} left`,
});
wss.clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN) {
client.send(leavePayload);
}
});
});
});
server.listen(PORT, () => {
console.log(`Chat server running at http://localhost:${PORT}`);
});
Build a Chat App project tests failing with __observer.once is not a function despite being up to date
Lesson URL (copy - paste from your browser’s address bar)