{"record":{"id":"c5b6e045060f628f","repo":"solidjs/solid","slug":"attempting-to-use-server-context-in-non-server-bui","errorCode":null,"errorMessage":"Attempting to use server context in non-server build","messagePattern":"Attempting to use server context in non-server build","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/solid/web/storage/src/index.ts","lineNumber":7,"sourceCode":"import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { RequestEvent } from \"solid-js/web\";\nimport { isServer, RequestContext } from \"solid-js/web\";\n\n// using global on a symbol for locating it later and detaching for environments that don't support it.\nexport function provideRequestEvent<T extends RequestEvent, U>(init: T, cb: () => U): U {\n  if (!isServer) throw new Error(\"Attempting to use server context in non-server build\");\n  const ctx: AsyncLocalStorage<T> = ((globalThis as any)[RequestContext] =\n    (globalThis as any)[RequestContext] || new AsyncLocalStorage<T>());\n  return ctx.run(init, cb);\n}\n","sourceCodeStart":1,"sourceCodeEnd":12,"githubUrl":"https://github.com/solidjs/solid/blob/f47845f9cc16ecbb316aa6560c7161f45af9a3d8/packages/solid/web/storage/src/index.ts#L1-L12","documentation":"provideRequestEvent uses node:async_hooks AsyncLocalStorage to expose the request event during SSR, so it only works when isServer is true (server conditions resolved by the bundler). Importing or calling it in a client bundle throws immediately to flag the environment mismatch.","triggerScenarios":"Calling provideRequestEvent(req, cb) in code bundled for the browser; server utilities imported eagerly into shared/isomorphic modules; using solid-js/web/storage helpers (useRequestEvent outside a provided run) in a client entry.","commonSituations":"Bundler 'solid' export condition resolving to browser because the file was imported from client code; testing server middleware in a browser-targeted vitest config; pulling a server-only helper into a shared util file.","solutions":["Move provideRequestEvent usage into server-only modules and keep them out of client entry graphs","Guard with isServer: if (isServer) provideRequestEvent(...) else fallback","Add 'solid' server conditions (e.g. via vite-plugin-solid conditions: ['node', 'solid']) so server builds resolve solid-js/web to server code"],"exampleFix":"// before (shared util imported by client)\nexport function handler(req, cb) {\n  return provideRequestEvent(req, cb); // throws in browser build\n}\n\n// after\nimport { isServer } from 'solid-js/web';\nexport function handler(req, cb) {\n  return isServer\n    ? provideRequestEvent(req, cb)\n    : cb();\n}","handlingStrategy":"validation","validationCode":"import { isServer } from 'solid-js/web';\nexport const runWithReq = isServer\n  ? (req: RequestEvent, cb: () => any) => provideRequestEvent(req, cb)\n  : (_req: unknown, cb: () => any) => cb();","typeGuard":"import { isServer } from 'solid-js/web';\nconst canProvideRequestEvent = (): boolean => isServer;","tryCatchPattern":"try { return provideRequestEvent(req, cb); } catch (e) { if (/server context in non-server/.test(String(e))) return cb(); throw e; }","preventionTips":["Keep server-only imports out of client entry graphs (split entry points)","Guard with isServer before calling server utilities","Configure bundler conditions so server builds resolve solid server code"],"tags":["solid","ssr","isserver","bundling","request-event"],"backgroundTag":"server-code-in-client-bundle","analyzedSha":"f47845f9cc16ecbb316aa6560c7161f45af9a3d8","analyzedAt":"2026-08-27T05:39:24.283Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}