This repository is a reduced reproduction for a TanStack Start + Storybook bug.
When a TanStack Start server function module defines a helper outside createServerFn(...).handler(), Storybook keeps the node:crypto import in the browser bundle instead of tree-shaking it away.
When the same logic is moved inline into the handler, Storybook no longer reports the browser-compatibility warning.
- Broken server function:
src/server/storybook/broken.functions.ts - Working server function:
src/server/storybook/works.functions.ts - Broken Storybook story:
src/stories/Broken.stories.tsx - Working Storybook story:
src/stories/Works.stories.tsx - Shared app route:
src/routes/index.tsx
-
Install dependencies.
npm install
-
Build Storybook.
npm run build-storybook
-
Observe the Storybook build output.
Storybook emits a browser-compatibility warning for the broken flow:
Module "node:crypto" has been externalized for browser compatibility, imported by
".../src/server/storybook/broken.functions.ts".
The broken story still builds, but it demonstrates that the hoisted helper is not removed from the client-side Storybook bundle.
Storybook should tree-shake server-only code in TanStack Start server function modules the same way TanStack Start does in the normal application build, regardless of whether the helper is declared outside the handler or inline within it.
At minimum, the broken flow should not pull node:crypto into the browser-side Storybook bundle.
The working control case moves the fingerprint logic inline inside the handler:
src/server/storybook/works.functions.ts
That version does not trigger the node:crypto browser warning during Storybook build.
The normal TanStack Start application route at src/routes/index.tsx renders both flows and builds successfully, showing that the behavior difference is specific to the Storybook integration path.
TypeScript check:
./node_modules/.bin/tsc --noEmit --pretty falseApp build:
./node_modules/.bin/vite build --debug --clearScreen falseStorybook build:
./node_modules/.bin/storybook build