Repository navigation
Open
ntatoud/noe.tatoud.com
#131Description
Which project does this relate to?
Start
Describe the bug
When trying to build a TanStack Start project in SPA mode with Docker Vite fails to connect to the server. The build works fine outside of Docker.
3.276 [nitro] ✔ You can preview this build using bun run .output/server/index.mjs
3.277 [prerender] Prerendering pages...
3.305
3.305 ╭───────────────── [Build Info] ────────────────────╮
3.305 │ │
3.305 │ - Build Directory: .output │
3.305 │ - Date: 1/2/2026, 5:55:52 AM │
3.305 │ - Nitro Version: 3.0.1-20251230-165713-6e801e22 │
3.305 │ - Nitro Preset: bun │
3.305 │ │
3.305 ╰───────────────────────────────────────────────────╯
3.305
3.305 ℹ Spawning preview server...
3.305 ℹ bun run ./server/index.mjs
3.305
3.324 ➜ Listening on: http://localhost:46317/ (all interfaces)
3.841 [prerender] Concurrency: 10
3.842 [prerender] Crawling: /
3.855 [prerender] Prerendered 0 pages:
3.859 error: Unable to connect. Is the computer able to access the url?
3.859 path: "http://localhost:3000/",
3.859 errno: 0,
3.859 code: "ConnectionRefused"
I've also tried forcing the Nitro port to run at 3000 which ends up with the Vite prerender server failing to start instead.
Your Example Website or App
Steps to Reproduce the Bug or Issue
- Download repository
- Build the docker image with
docker build -t tanstack-start/nitro .
Expected behavior
I expect it to be able to connect to the server and to the pre-rendering.
Screenshots or Videos
No response
Platform
- Router / Start Version: Router 1.132.0 and Start 1.132.0
- Nitro: Nightly at latest
- Runtime: Bun
- OS: Mac OS
- Bundler: Vite
- Bundler Version: 7.1.7
Additional context
Similar to the following issue:
#5967 (comment)
Reacted by Tekena Solomon and Lilian Prus
Metadata
Metadata
Assignees
Labels
No labels
Activity
schiller-manuel commentedon Jan 2, 2026
does this work if not using nitro (just comment the plugin out) ? or does prerendering not work in general in docker?
NormySan commentedon Jan 2, 2026
I just tried commenting out the Nitro Vite plugin and build again and that doesn't work either. I'm guessing that nitro is needed for the pre-rendering since it doesn't even start a server for the pre-renderer to visit when Nitro is not being used.
schiller-manuel commentedon Jan 2, 2026
nitro is not needed for prerendering. so most likely the vite preview server that is used for prerendering is not accessible in the docker env
cc @edmundhung
edmundhung commentedon Jan 5, 2026
#6305 should fix it.
In the meantime, you can workaround it by removing the nitro plugin and set
preview.hosttotrue:const config = defineConfig({ + preview: { + host: true, + }, plugins: [ devtools(), - nitro({ preset: "bun" }),The docker build is still falling with
COPY --from=build /app/apps/web/.output .but it seems unrelated andbun run buildstep is already passed.isc30 commentedon Feb 3, 2026
Even after following these steps trying to get sitemap working, the
sitemap.xmlis not available in.output/server/sitemap.xmland only in.output/public/sitemap.xml. This means thatnode .output/server/index.mjsis not serving it on/sitemap.xml.Using
also tried running this after
npm run buildbut doesnt work as the assets are explicitly listed in the server.mjs output:COPY .output/public/sitemap.xml .output/server/sitemap.xmledmundhung commentedon Feb 3, 2026
@isc30 Does that work if you remove the nitro plugin? Are you building it in a docker container too?
isc30 commentedon Feb 3, 2026
doesn't work outside of docker either.
without the nitro plugin im not sure how to run the server, as it returns 0 instantly
xonio-x commentedon Feb 3, 2026
I try to remove the nitro plugin, and set the preview host, and for the bun user you can copy the server.ts from bun starter and it just work in dockerfile you guys just need to copy the dist folder, node modules and the server.ts
But hopefully someone able to make it work with nitro 🥲I don't link copy the node modules 😅
isc30 commentedon Feb 3, 2026
Hey @xonio-x how do you run the server without nitro?
I get a
distfolder and then try to run withnode ./dist/server/server.js, which does nothing.conioX commentedon Feb 4, 2026
i use server.ts from the bun and i use runtime bun not node js so i dont know it possible with the node js @isc30
conioX commentedon Feb 4, 2026
you can follow this node js based but require hono, and follow this readme.md file https://github.com/TanStack/router/tree/main/examples/react/start-bun this should work without nitro @isc30
CarlosZiegler commentedon Feb 20, 2026
Hey, ran into this exact issue with TanStack Start v1.161.1 + Bun 1.3.9 in a multi-stage Docker build. The prerender step was trying to hit http://localhost:35537/ (random port) and getting
ConnectionRefused.Adding
preview.hostto the vite config fixed it:Forces the preview server to explicitly bind to the loopback address inside the container. After that, all pages prerender fine during docker build. Hope this helps someone.
fix: resolve docs build and formatter issues
fix: disable prerender — blocked by nitro@3 + TanStack Start race con…
fix: patch tanstack start prerender to bind preview server to 127.0.0…
Pin react-router's prerender preview server to IPv4 loopback
[vite 8.2.0] Fix REFLEX_ENV_MODE leak between AppHarness instances (#…
alxwlw commentedon Nov 26, 2026
This adds the exact condition under which the prerender request is refused, and where Node and Bun stand on current releases, in case it helps with documenting the Docker case as discussed in #6305.
Versions:
@tanstack/react-start1.169.7,@tanstack/start-plugin-core1.172.0,vite8.4.0. Minimal SPA-mode app (tanstackStart({ spa: { enabled: true } }), one route),vite buildinsidedocker run --rm ubuntu:24.04on Docker's default bridge network (Docker 29.10.0, Linux x64 host).Result on Node 22.23.3, 24.22.2 and 26.8.1: exit code 1, here from the 26.8.1 run:
Why: in 1.172.0 the plugin starts
vite.preview({ preview: { port: 0, open: false } })and requestspreviewServer.resolvedUrls.local[0]. In that container Vite reportshttp://localhost:<port>/while its socket is bound to::1, becauselocalhostresolves differently for listening and for connecting:listen("localhost")binds the first address of the plain lookup (::1).net.connectresolves with thedns.ADDRCONFIGhint, and with it the::1result is gone as long aslois the only interface that has an IPv6 address. That is what a container on Docker's default bridge looks like here:net.ipv6.conf.eth0.disable_ipv6is1, while/etc/hostsstill maps::1tolocalhost. Both parts are needed; changing either one makes the same build printPrerendered 1 pages(Node 26.8.1):::1line does not namelocalhost: both lookups return only127.0.0.1;eth0(a link-local address is enough): both lookups return::1first.Bun, same container and project (
bun --bun node_modules/vite/bin/vite.js build): 1.3.5, 1.3.9 and 1.4.0 fail with the message quoted in this thread (Unable to connect. Is the computer able to access the url?,path: "http://localhost:<port>/",code: "ConnectionRefused"); 1.4.1 and 1.4.5 prerender the page.Workarounds:
preview: { host: '127.0.0.1' }from the comment above passes on these versions (run on Node 26.8.1). Without touching the Vite config,NODE_OPTIONS=--dns-result-order=ipv4firstfor the build step passes too (Node 26.8.1): the preview server then binds127.0.0.1.Not run:
docker build/ BuildKit itself (onlydocker run), Docker Desktop on macOS, the Nitro plugin setup from the original report,preview.host: true, the branch of #6305. What the plugin calls is read from the published 1.172.0 package, and the listen side from Node'slib/net.js; theADDRCONFIGhint on connect was logged through a customlookupon Node 26.8.1.