Skip to content

stop the service-utils orpc barrel evaluating server trace storage in the browser #865

Description

@zgeoff

Observed

The browser console reports, once per session on the world-map screen:

Uncaught Error: Module "node:async_hooks" has been externalized for browser compatibility. Cannot access "node:async_hooks.AsyncLocalStorage" in client code.

Vite's client dep cache also picks up server-only modules (@opentelemetry/sdk-trace-node, undici, @openfeature/server-sdk) into the browser graph.

Expected

No server-only module is evaluated in the browser or the SharedWorker; the console stays clean.

Repro

  1. bun run stack start and bun run dev:app-web.
  2. Log in and open /explore with devtools on.
  3. The externalized-module error appears in the console (it originates from the idle SharedWorker's module graph, so a Playwright page-console listener does not capture it).

Notes

The chain: the idle SharedWorker's activity client (libs/game/idle-client/src/submission/create-activity-service-client.ts) imports buildRetryInterceptor/makeIsRetryable from @vers/service-utils/orpc; that barrel also re-exports buildTracingInterceptor, whose imports end at libs/service/service-utils/src/trace/trace-storage.ts constructing AsyncLocalStorage at module scope. Browser-safe consumers of the retry interceptor evaluate server-only trace storage as a side effect of the barrel. Introduced with the shared retry interceptor (#811/#813).

The error is non-fatal today, but worth verifying the worker's submission path is genuinely unaffected. Likely fixes: split the browser-safe orpc helpers from the tracing interceptor (separate export path), or make the trace storage lazy so importing the barrel never touches node:async_hooks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/platformarea: deploy, db hosting, monorepo, CIbugbzzzzp2-mediumpriority: medium

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions