Description
Which project does this relate to?
Start
Describe the bug
Packages installed in node_modules
rely on sharing a server context with the main application, such as using AsyncLocalStorage
for request-scoped data, auth, or other per-request state. If Vite externalizes these packages during SSR (its default behavior), they may be loaded in a separate context, causing them to lose access to the shared server state.
This can result in runtime errors like:
Error: No HTTPEvent found in AsyncLocalStorage. Make sure you are using the function within the server runtime.
at getEvent (node_modules/@tanstack/start-server-core/dist/esm/h3.js:30:11)
...
Temporary Workaround:
Add the affected package to the ssr.noExternal
option in your vite.config.ts
file:
export default defineConfig({
// ...other config
ssr: {
noExternal: ['@clerk/tanstack-react-start'],
},
});
Your Example Website or App
https://codesandbox.io/p/devbox/mdxyzw
Steps to Reproduce the Bug or Issue
- Create a fresh devinxi based TanStack Start app
- Install Clerk SDK with devinxi support (
npm i @clerk/tanstack-react-start@0.17.0-snapshot.v20250611045520 --save-exact
) - Run
npm run dev
- Check console
or visit the codesandbox link
Expected behavior
Packages that depend on shared server context should function correctly during SSR, with no loss of context or unexpected errors, even if they are installed in node_modules
.
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Chrome
Additional context
No response