`createServerFn` @tanstack/start-server-core leaking into client bundle
Which project does this relate to?
Start
Describe the bug
When using createServerFn some of the server code is leaking into the client bundle as shown in the warning messages and error below:
❯ pnpm run build
\
> @theaistudybible/www@ build /Users/ianpascoe/Code/theaistudybible/apps/www
> vinxi build
vinxi v0.5.4
⚙ Building your app...
vinxi v0.5.4
⚙ Building your router client...
📦 Compiling client router...
vinxi building router client in client mode
♻️ Generating routes...
✅ Processed routes in 139ms
vite v6.2.6 building for production...
[plugin vite:resolve] Module "node:fs" has been externalized for browser compatibility, imported by "/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-client-core/dist/esm/createServerFn.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin vite:resolve] Module "node:path" has been externalized for browser compatibility, imported by "/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-client-core/dist/esm/createServerFn.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin vite:resolve] Module "node:fs" has been externalized for browser compatibility, imported by "/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-client-core/dist/esm/createServerFn.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin vite:resolve] Module "node:path" has been externalized for browser compatibility, imported by "/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-client-core/dist/esm/createServerFn.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin vite:resolve] Module "node:stream" has been externalized for browser compatibility, imported by "/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@tanstack/react-start-server/dist/esm/defaultStreamHandler.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin vite:resolve] Module "node:stream/web" has been externalized for browser compatibility, imported by "/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-server-core/dist/esm/transformStreamWithRouter.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin vite:resolve] Module "node:stream" has been externalized for browser compatibility, imported by "/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-server-core/dist/esm/transformStreamWithRouter.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin vite:resolve] Module "node:async_hooks" has been externalized for browser compatibility, imported by "/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-server-core/dist/esm/h3.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
✓ 3051 modules transformed.
PWA v1.0.0
Building app/service-worker.ts service worker ("es" format)...
vite v6.2.6 building for production...
✓ 70 modules transformed.
.vinxi/build/client/_build/service-worker.mjs 17.12 kB │ gzip: 5.78 kB
✓ built in 101ms
PWA v1.0.0
mode injectManifest
format: es
precache 2 entries (0.00 KiB)
files generated
.vinxi/build/client/_build/service-worker.js
warnings
One of the glob patterns doesn't match any files. Please remove or fix the following: {
"globDirectory": "/Users/ianpascoe/Code/theaistudybible/apps/www/.vinxi/build/client/_build",
"globPattern": "**/*.{js,css,html,png,svg,ico,wasm,webp,woff,woff2,ttf,eot,json,jpg,jpeg,gif,mp3,mp4,wav,avif}",
"globIgnores": [
"**/node_modules/**/*",
"service-worker.js",
"service-worker.js"
]
}
✗ Build failed in 6.79s
ERROR [vite-plugin-pwa:build] There was an error during the build: 11:32:32 AM
../../node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-server-core/dist/esm/transformStreamWithRouter.js (2:9): "Readable" is not exported by "__vite-browser-external", imported by "../../node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-server-core/dist/esm/transformStreamWithRouter.js".
Additionally, handling the error in the 'buildEnd' hook caused the following error:
../../node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-server-core/dist/esm/transformStreamWithRouter.js (2:9): "Readable" is not exported by "__vite-browser-external", imported by "../../node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-server-core/dist/esm/transformStreamWithRouter.js".
file: /Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-server-core/dist/esm/transformStreamWithRouter.js:2:9
1: import { ReadableStream } from "node:stream/web";
2: import { Readable } from "node:stream";
^
3: import { createControlledPromise } from "@tanstack/router-core";
4: function transformReadableStreamWithRouter(router, routerStream) {
at getRollupError (/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/parseAst.js:397:41)
at /Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:23076:39
at async catchUnfinishedHookActions (/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:22540:16)
at async rollupInternal (/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:23059:5)
at async buildEnvironment (/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/vite/dist/node/chunks/dep-Bid9ssRr.js:51506:14)
at async createViteBuild (/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected][email protected]_@_d95f9dbdce65deaf792ada549192fef2/node_modules/vinxi/lib/build.js:395:17)
at async createRouterBuild (/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected][email protected]_@_d95f9dbdce65deaf792ada549192fef2/node_modules/vinxi/lib/build.js:529:2)
at async /Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected][email protected]_@_d95f9dbdce65deaf792ada549192fef2/node_modules/vinxi/lib/build.js:59:5
at async createBuild (/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected][email protected]_@_d95f9dbdce65deaf792ada549192fef2/node_modules/vinxi/lib/build.js:58:4)
at async Object.run (/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected][email protected]_@_d95f9dbdce65deaf792ada549192fef2/node_modules/vinxi/bin/cli.mjs:235:5)
at async runCommand (/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/[email protected]/node_modules/citty/dist/index.mjs:316:16)
at async runCommand (/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/[email protected]/node_modules/citty/dist/index.mjs:307:11)
at async runMain (/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/[email protected]/node_modules/citty/dist/index.mjs:445:7)
ERROR [vite-plugin-pwa:build] There was an error during the build: 11:32:32 AM
../../node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-server-core/dist/esm/transformStreamWithRouter.js (2:9): "Readable" is not exported by "__vite-browser-external", imported by "../../node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-server-core/dist/esm/transformStreamWithRouter.js".
Additionally, handling the error in the 'buildEnd' hook caused the following error:
../../node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-server-core/dist/esm/transformStreamWithRouter.js (2:9): "Readable" is not exported by "__vite-browser-external", imported by "../../node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-server-core/dist/esm/transformStreamWithRouter.js".
file: /Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/@[email protected]/node_modules/@tanstack/start-server-core/dist/esm/transformStreamWithRouter.js:2:9
1: import { ReadableStream } from "node:stream/web";
2: import { Readable } from "node:stream";
^
3: import { createControlledPromise } from "@tanstack/router-core";
4: function transformReadableStreamWithRouter(router, routerStream) {
ERROR Exited with code: 1 11:32:32 AM
at CommandChild.pipedStdoutBuffer (/Users/ianpascoe/Code/theaistudybible/node_modules/.pnpm/[email protected]/node_modules/dax-sh/esm/mod.js:9392:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
ERROR Exited with code: 1
Your Example Website or App
https://github.com/spirit-led-software/theaistudybible
Steps to Reproduce the Bug or Issue
- Run
pnpm buildfrom withinapps/www - Observer the failure
Expected behavior
As a user, I expected my production build to build successfully and not have server/client bundle issues
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Vivaldi
- Version: 7
Additional context
No response
I had the same problem, I think you are trying to use some server function like getHeader on the client.
I'm running into the same issue, can reproduce using the start-basic example:
-
npx gitpick TanStack/router/tree/main/examples/react/start-basic start-basic -
cd start-basic -
npm install -
npm build
start-basic % npm run build
> build
> vinxi build
vinxi v0.5.3
⚙ Building your app...
removing /Users/tobias/Documents/Development/start-basic/.vinxi/build/client
removing /Users/tobias/Documents/Development/start-basic/.vinxi/build/ssr
removing /Users/tobias/Documents/Development/start-basic/.vinxi/build/server
removing /Users/tobias/Documents/Development/start-basic/.vinxi/build/api
vinxi v0.5.3
⚙ Building your router client...
📦 Compiling client router...
vinxi building router client in client mode
♻️ Generating routes...
✅ Processed routes in 156ms
vite v6.3.4 building for production...
[plugin vite:resolve] Module "node:fs" has been externalized for browser compatibility, imported by "/Users/tobias/Documents/Development/start-basic/node_modules/@tanstack/start-client-core/dist/esm/createServerFn.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin vite:resolve] Module "node:path" has been externalized for browser compatibility, imported by "/Users/tobias/Documents/Development/start-basic/node_modules/@tanstack/start-client-core/dist/esm/createServerFn.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin vite:resolve] Module "node:fs" has been externalized for browser compatibility, imported by "/Users/tobias/Documents/Development/start-basic/node_modules/@tanstack/start-client-core/dist/esm/createServerFn.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin vite:resolve] Module "node:path" has been externalized for browser compatibility, imported by "/Users/tobias/Documents/Development/start-basic/node_modules/@tanstack/start-client-core/dist/esm/createServerFn.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
virtual:$vinxi/handler/client (1:106): "default" is not exported by "src/client.tsx", imported by "virtual:$vinxi/handler/client".
✓ 189 modules transformed.
.vinxi/build/client/_build/.vite/manifest.json 7.47 kB │ gzip: 0.95 kB
.vinxi/build/client/_build/assets/app-DU2gGyHe.css 7.30 kB │ gzip: 2.09 kB
.vinxi/build/client/_build/assets/__vite-browser-external-BIHI7g3E.js 0.03 kB │ gzip: 0.05 kB
.vinxi/build/client/_build/assets/client-CLK42Prl.js 0.06 kB │ gzip: 0.08 kB
.vinxi/build/client/_build/assets/posts._postId-DNaHGGLA.js 0.11 kB │ gzip: 0.12 kB
.vinxi/build/client/_build/assets/posts_._postId.deep-E5joyy4z.js 0.11 kB │ gzip: 0.12 kB
.vinxi/build/client/_build/assets/PostError-CDtlP0eQ.js 0.11 kB │ gzip: 0.12 kB
.vinxi/build/client/_build/assets/route-b-CSpC05IQ.js 0.13 kB │ gzip: 0.13 kB
.vinxi/build/client/_build/assets/route-a-DBPMMR1Z.js 0.13 kB │ gzip: 0.13 kB
.vinxi/build/client/_build/assets/users._userId-CM751gHQ.js 0.13 kB │ gzip: 0.14 kB
.vinxi/build/client/_build/assets/posts._postId-TbZnoE70.js 0.13 kB │ gzip: 0.13 kB
.vinxi/build/client/_build/assets/users.index-C88qWrm3.js 0.13 kB │ gzip: 0.14 kB
.vinxi/build/client/_build/assets/posts.index-DjZIXhUy.js 0.13 kB │ gzip: 0.14 kB
.vinxi/build/client/_build/assets/users._userId-DzT_OH2F.js 0.14 kB │ gzip: 0.13 kB
.vinxi/build/client/_build/assets/index-DzBMORpB.js 0.17 kB │ gzip: 0.16 kB
.vinxi/build/client/_build/assets/_pathlessLayout-HuTKlhpS.js 0.24 kB │ gzip: 0.19 kB
.vinxi/build/client/_build/assets/users._userId-DkLITMWk.js 0.30 kB │ gzip: 0.22 kB
.vinxi/build/client/_build/assets/posts_._postId.deep-CAEATBr3.js 0.41 kB │ gzip: 0.29 kB
.vinxi/build/client/_build/assets/_nested-layout-BkTaFxnb.js 0.45 kB │ gzip: 0.26 kB
.vinxi/build/client/_build/assets/posts._postId-Cj79Vi-Q.js 0.49 kB │ gzip: 0.32 kB
.vinxi/build/client/_build/assets/users.route-B7WNoi_E.js 0.60 kB │ gzip: 0.39 kB
.vinxi/build/client/_build/assets/posts.route-CilHwWe-.js 0.60 kB │ gzip: 0.39 kB
.vinxi/build/client/_build/assets/deferred-DKLB-S2l.js 0.82 kB │ gzip: 0.40 kB
.vinxi/build/client/_build/assets/client-B8y9h1oh.js 278.76 kB │ gzip: 89.29 kB
✓ built in 905ms
✔ build done 1:13:19 PM
⚙ Built your router client successfully
vinxi v0.5.3
⚙ Building your router ssr...
📦 Compiling ssr router...
vinxi building router ssr in http mode
vite v6.3.4 building SSR bundle for production...
"clientOnly", "createIsomorphicFn", "globalMiddleware", "json" and "serverOnly" are imported from external module "@tanstack/start-client-core" but never used in "node_modules/@tanstack/react-start-client/dist/esm/StartClient.js", "node_modules/@tanstack/react-start-client/dist/esm/index.js", "node_modules/@tanstack/start-server-functions-fetcher/dist/esm/index.js" and "node_modules/@tanstack/start-server-functions-ssr/dist/esm/index.js".
✓ 67 modules transformed.
.vinxi/build/ssr/.vite/manifest.json 6.55 kB
.vinxi/build/ssr/assets/app-DU2gGyHe.css 7.30 kB
.vinxi/build/ssr/assets/route-b-D9PRTkM1.js 0.12 kB
.vinxi/build/ssr/assets/route-a-E7oJVDbm.js 0.12 kB
.vinxi/build/ssr/assets/users.index-C_G0zRko.js 0.13 kB
.vinxi/build/ssr/assets/posts.index-GrcD0GTd.js 0.13 kB
.vinxi/build/ssr/assets/posts._postId-CCFyNDhO.js 0.14 kB
.vinxi/build/ssr/assets/posts_._postId.deep-CCFyNDhO.js 0.14 kB
.vinxi/build/ssr/assets/PostError-DXPFgQzs.js 0.16 kB
.vinxi/build/ssr/assets/index-CuMTP0jl.js 0.16 kB
.vinxi/build/ssr/assets/users._userId-CxO9mclU.js 0.18 kB
.vinxi/build/ssr/assets/_pathlessLayout-BhUDWYaS.js 0.27 kB
.vinxi/build/ssr/ssr.js 0.35 kB
.vinxi/build/ssr/assets/users._userId-C44Gwmbi.js 0.41 kB
.vinxi/build/ssr/assets/posts._postId-DMFJUzkr.js 0.41 kB
.vinxi/build/ssr/assets/_nested-layout-BHe2HPJb.js 0.47 kB
.vinxi/build/ssr/assets/users._userId-aLGGtNIx.js 0.58 kB
.vinxi/build/ssr/assets/posts_._postId.deep-BlGBrBVX.js 0.70 kB
.vinxi/build/ssr/assets/posts._postId-CpcxQml2.js 0.77 kB
.vinxi/build/ssr/assets/users.route-Di_yysHc.js 0.88 kB
.vinxi/build/ssr/assets/posts.route-Dgd06a6V.js 0.88 kB
.vinxi/build/ssr/assets/deferred-DNLgJPzn.js 1.08 kB
.vinxi/build/ssr/assets/ssr-CKliUiKE.js 14.09 kB
✓ built in 410ms
✔ build done 1:13:20 PM
⚙ Built your router ssr successfully
vinxi v0.5.3
⚙ Building your router server...
📦 Compiling server router...
vinxi building router server in http mode
vite v6.3.4 building SSR bundle for production...
"clientOnly", "createIsomorphicFn", "globalMiddleware", "json", "mergeHeaders" and "serverOnly" are imported from external module "@tanstack/start-client-core" but never used in "node_modules/@tanstack/react-start-client/dist/esm/StartClient.js", "node_modules/@tanstack/react-start-client/dist/esm/index.js" and "node_modules/@tanstack/start-server-functions-handler/dist/esm/index.js".
✓ 18 modules transformed.
.vinxi/build/server/_server/.vite/manifest.json 1.37 kB
.vinxi/build/server/_server/assets/index-ujMS-7Qz.js 0.28 kB
.vinxi/build/server/_server/assets/posts-BA7Lzkzg.js 0.96 kB
.vinxi/build/server/_server/assets/deferred-B8VZvB08.js 1.06 kB
.vinxi/build/server/_server/assets/deferred-CUk1YZ6L.js 1.85 kB
.vinxi/build/server/_server/server.js 3.82 kB
✓ built in 223ms
✔ build done 1:13:21 PM
⚙ Built your router server successfully
vinxi v0.5.3
⚙ Building your router api...
📦 Compiling api router...
vinxi building router api in http mode
vite v6.3.4 building SSR bundle for production...
"clientOnly", "createIsomorphicFn", "createMiddleware", "createServerFn", "globalMiddleware", "mergeHeaders", "registerGlobalMiddleware", "serverOnly" and "startSerializer" are imported from external module "@tanstack/start-client-core" but never used in "node_modules/@tanstack/react-start-client/dist/esm/StartClient.js" and "node_modules/@tanstack/react-start-client/dist/esm/index.js".
✓ 14 modules transformed.
.vinxi/build/api/api/.vite/manifest.json 1.02 kB
.vinxi/build/api/api/api.js 0.13 kB
.vinxi/build/api/api/users.js 0.46 kB
.vinxi/build/api/api/users._id.js 0.55 kB
.vinxi/build/api/api/assets/index-C_-U9-id.js 4.05 kB
✓ built in 171ms
✔ build done 1:13:22 PM
⚙ Built your router api successfully
⚙ Preparing app for node-server...
✔ Generated public .output/public vinxi 1:13:22 PM
ℹ Building Nitro Server (preset: node-server, compatibility date: 2024-12-01) vinxi 1:13:22 PM
✔ Nitro Server built vinxi 1:13:23 PM
✔ You can preview this build using node .output/server/index.mjs vinxi 1:13:23 PM```
+1, same issue here.
I had the same problem, I think you are trying to use some server function like getHeader on the client.
This solved it for me. I was using getCookie in the client. Tried to section it into a block where typeof window === "undefined", but it didn't split the code out.
I'm running into the same issue, can reproduce using the start-basic example:
npx gitpick TanStack/router/tree/main/examples/react/start-basic start-basiccd start-basicnpm installnpm buildstart-basic % npm run build > build > vinxi build vinxi v0.5.3 ⚙ Building your app... removing /Users/tobias/Documents/Development/start-basic/.vinxi/build/client removing /Users/tobias/Documents/Development/start-basic/.vinxi/build/ssr removing /Users/tobias/Documents/Development/start-basic/.vinxi/build/server removing /Users/tobias/Documents/Development/start-basic/.vinxi/build/api vinxi v0.5.3 ⚙ Building your router client... 📦 Compiling client router... vinxi building router client in client mode ♻️ Generating routes... ✅ Processed routes in 156ms vite v6.3.4 building for production... [plugin vite:resolve] Module "node:fs" has been externalized for browser compatibility, imported by "/Users/tobias/Documents/Development/start-basic/node_modules/@tanstack/start-client-core/dist/esm/createServerFn.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. [plugin vite:resolve] Module "node:path" has been externalized for browser compatibility, imported by "/Users/tobias/Documents/Development/start-basic/node_modules/@tanstack/start-client-core/dist/esm/createServerFn.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. [plugin vite:resolve] Module "node:fs" has been externalized for browser compatibility, imported by "/Users/tobias/Documents/Development/start-basic/node_modules/@tanstack/start-client-core/dist/esm/createServerFn.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. [plugin vite:resolve] Module "node:path" has been externalized for browser compatibility, imported by "/Users/tobias/Documents/Development/start-basic/node_modules/@tanstack/start-client-core/dist/esm/createServerFn.js". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. virtual:$vinxi/handler/client (1:106): "default" is not exported by "src/client.tsx", imported by "virtual:$vinxi/handler/client". ✓ 189 modules transformed. .vinxi/build/client/_build/.vite/manifest.json 7.47 kB │ gzip: 0.95 kB .vinxi/build/client/_build/assets/app-DU2gGyHe.css 7.30 kB │ gzip: 2.09 kB .vinxi/build/client/_build/assets/__vite-browser-external-BIHI7g3E.js 0.03 kB │ gzip: 0.05 kB .vinxi/build/client/_build/assets/client-CLK42Prl.js 0.06 kB │ gzip: 0.08 kB .vinxi/build/client/_build/assets/posts._postId-DNaHGGLA.js 0.11 kB │ gzip: 0.12 kB .vinxi/build/client/_build/assets/posts_._postId.deep-E5joyy4z.js 0.11 kB │ gzip: 0.12 kB .vinxi/build/client/_build/assets/PostError-CDtlP0eQ.js 0.11 kB │ gzip: 0.12 kB .vinxi/build/client/_build/assets/route-b-CSpC05IQ.js 0.13 kB │ gzip: 0.13 kB .vinxi/build/client/_build/assets/route-a-DBPMMR1Z.js 0.13 kB │ gzip: 0.13 kB .vinxi/build/client/_build/assets/users._userId-CM751gHQ.js 0.13 kB │ gzip: 0.14 kB .vinxi/build/client/_build/assets/posts._postId-TbZnoE70.js 0.13 kB │ gzip: 0.13 kB .vinxi/build/client/_build/assets/users.index-C88qWrm3.js 0.13 kB │ gzip: 0.14 kB .vinxi/build/client/_build/assets/posts.index-DjZIXhUy.js 0.13 kB │ gzip: 0.14 kB .vinxi/build/client/_build/assets/users._userId-DzT_OH2F.js 0.14 kB │ gzip: 0.13 kB .vinxi/build/client/_build/assets/index-DzBMORpB.js 0.17 kB │ gzip: 0.16 kB .vinxi/build/client/_build/assets/_pathlessLayout-HuTKlhpS.js 0.24 kB │ gzip: 0.19 kB .vinxi/build/client/_build/assets/users._userId-DkLITMWk.js 0.30 kB │ gzip: 0.22 kB .vinxi/build/client/_build/assets/posts_._postId.deep-CAEATBr3.js 0.41 kB │ gzip: 0.29 kB .vinxi/build/client/_build/assets/_nested-layout-BkTaFxnb.js 0.45 kB │ gzip: 0.26 kB .vinxi/build/client/_build/assets/posts._postId-Cj79Vi-Q.js 0.49 kB │ gzip: 0.32 kB .vinxi/build/client/_build/assets/users.route-B7WNoi_E.js 0.60 kB │ gzip: 0.39 kB .vinxi/build/client/_build/assets/posts.route-CilHwWe-.js 0.60 kB │ gzip: 0.39 kB .vinxi/build/client/_build/assets/deferred-DKLB-S2l.js 0.82 kB │ gzip: 0.40 kB .vinxi/build/client/_build/assets/client-B8y9h1oh.js 278.76 kB │ gzip: 89.29 kB ✓ built in 905ms ✔ build done 1:13:19 PM ⚙ Built your router client successfully vinxi v0.5.3 ⚙ Building your router ssr... 📦 Compiling ssr router... vinxi building router ssr in http mode vite v6.3.4 building SSR bundle for production... "clientOnly", "createIsomorphicFn", "globalMiddleware", "json" and "serverOnly" are imported from external module "@tanstack/start-client-core" but never used in "node_modules/@tanstack/react-start-client/dist/esm/StartClient.js", "node_modules/@tanstack/react-start-client/dist/esm/index.js", "node_modules/@tanstack/start-server-functions-fetcher/dist/esm/index.js" and "node_modules/@tanstack/start-server-functions-ssr/dist/esm/index.js". ✓ 67 modules transformed. .vinxi/build/ssr/.vite/manifest.json 6.55 kB .vinxi/build/ssr/assets/app-DU2gGyHe.css 7.30 kB .vinxi/build/ssr/assets/route-b-D9PRTkM1.js 0.12 kB .vinxi/build/ssr/assets/route-a-E7oJVDbm.js 0.12 kB .vinxi/build/ssr/assets/users.index-C_G0zRko.js 0.13 kB .vinxi/build/ssr/assets/posts.index-GrcD0GTd.js 0.13 kB .vinxi/build/ssr/assets/posts._postId-CCFyNDhO.js 0.14 kB .vinxi/build/ssr/assets/posts_._postId.deep-CCFyNDhO.js 0.14 kB .vinxi/build/ssr/assets/PostError-DXPFgQzs.js 0.16 kB .vinxi/build/ssr/assets/index-CuMTP0jl.js 0.16 kB .vinxi/build/ssr/assets/users._userId-CxO9mclU.js 0.18 kB .vinxi/build/ssr/assets/_pathlessLayout-BhUDWYaS.js 0.27 kB .vinxi/build/ssr/ssr.js 0.35 kB .vinxi/build/ssr/assets/users._userId-C44Gwmbi.js 0.41 kB .vinxi/build/ssr/assets/posts._postId-DMFJUzkr.js 0.41 kB .vinxi/build/ssr/assets/_nested-layout-BHe2HPJb.js 0.47 kB .vinxi/build/ssr/assets/users._userId-aLGGtNIx.js 0.58 kB .vinxi/build/ssr/assets/posts_._postId.deep-BlGBrBVX.js 0.70 kB .vinxi/build/ssr/assets/posts._postId-CpcxQml2.js 0.77 kB .vinxi/build/ssr/assets/users.route-Di_yysHc.js 0.88 kB .vinxi/build/ssr/assets/posts.route-Dgd06a6V.js 0.88 kB .vinxi/build/ssr/assets/deferred-DNLgJPzn.js 1.08 kB .vinxi/build/ssr/assets/ssr-CKliUiKE.js 14.09 kB ✓ built in 410ms ✔ build done 1:13:20 PM ⚙ Built your router ssr successfully vinxi v0.5.3 ⚙ Building your router server... 📦 Compiling server router... vinxi building router server in http mode vite v6.3.4 building SSR bundle for production... "clientOnly", "createIsomorphicFn", "globalMiddleware", "json", "mergeHeaders" and "serverOnly" are imported from external module "@tanstack/start-client-core" but never used in "node_modules/@tanstack/react-start-client/dist/esm/StartClient.js", "node_modules/@tanstack/react-start-client/dist/esm/index.js" and "node_modules/@tanstack/start-server-functions-handler/dist/esm/index.js". ✓ 18 modules transformed. .vinxi/build/server/_server/.vite/manifest.json 1.37 kB .vinxi/build/server/_server/assets/index-ujMS-7Qz.js 0.28 kB .vinxi/build/server/_server/assets/posts-BA7Lzkzg.js 0.96 kB .vinxi/build/server/_server/assets/deferred-B8VZvB08.js 1.06 kB .vinxi/build/server/_server/assets/deferred-CUk1YZ6L.js 1.85 kB .vinxi/build/server/_server/server.js 3.82 kB ✓ built in 223ms ✔ build done 1:13:21 PM ⚙ Built your router server successfully vinxi v0.5.3 ⚙ Building your router api... 📦 Compiling api router... vinxi building router api in http mode vite v6.3.4 building SSR bundle for production... "clientOnly", "createIsomorphicFn", "createMiddleware", "createServerFn", "globalMiddleware", "mergeHeaders", "registerGlobalMiddleware", "serverOnly" and "startSerializer" are imported from external module "@tanstack/start-client-core" but never used in "node_modules/@tanstack/react-start-client/dist/esm/StartClient.js" and "node_modules/@tanstack/react-start-client/dist/esm/index.js". ✓ 14 modules transformed. .vinxi/build/api/api/.vite/manifest.json 1.02 kB .vinxi/build/api/api/api.js 0.13 kB .vinxi/build/api/api/users.js 0.46 kB .vinxi/build/api/api/users._id.js 0.55 kB .vinxi/build/api/api/assets/index-C_-U9-id.js 4.05 kB ✓ built in 171ms ✔ build done 1:13:22 PM ⚙ Built your router api successfully ⚙ Preparing app for node-server... ✔ Generated public .output/public vinxi 1:13:22 PM ℹ Building Nitro Server (preset: node-server, compatibility date: 2024-12-01) vinxi 1:13:22 PM ✔ Nitro Server built vinxi 1:13:23 PM ✔ You can preview this build using node .output/server/index.mjs vinxi 1:13:23 PM```
sorry for my stupidity, where does it leaked?
Having the same issue.
Same issue here with a fresh install following the start-basic guide
I experienced something similar when using setCookie. Manage to resolve it by wrapping the function in a serverOnly function. Hope this helps
export const setTokens = serverOnly(async (access: string, refresh: string) => {
setCookie("access_token", access, {
httpOnly: true,
sameSite: "lax",
path: "/",
maxAge: 34560000,
});
setCookie("refresh_token", refresh, {
httpOnly: true,
sameSite: "lax",
path: "/",
maxAge: 34560000,
});
});
To avoid importing server modules in client side, try to create the src/server.ts server entry file (v1.121.1+), and import them there, see https://github.com/TanStack/router/issues/2783#issuecomment-3032372138
same issue code in createserverfn leaking into client
Creating a separate file for only server function and default exporting it works for me
Is this still an issue in the latest version of start? It no longer uses vinxi
This was still an issue for me using Vite. Using import.meta.env.SSR instead of typeof window == 'undefined' (and dynamically importing any server-only functions within an if (import.meta.env.SSR) {...} statement) fixed it.