preset: bun preset uses incorrect ReadableStream parameters

Aperta
#4,259 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

  • #4265 di @harshagarwalnyu — chiusa senza merge

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
bun, node.js, react, typescript

Direzione di ricerca

Inizia individuando il Nitro bun preset e l’integrazione generata di React DOM Server che crea il ReadableStream con il tipo "direct". Riproduci il problema con il prerendering di TanStack Start abilitato, quindi verifica che il bun preset produca parametri di stream validi e che la build di prerendering venga completata senza ERR_INVALID_ARG_VALUE.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug needs investigation tanstack v3
Environment

Bun v1.3.13
Node v24.15.0

Nitro:
Working version: v3.0.1-alpha.2
Broken version: v3.0.260311-beta (and later versions)

Reproduction

Since I am working on a private project, I cannot share the environement, but this should work in any Tanstack Start + Nitro project. You just need to enable prerendering and try to build the project.

tanstackStart({
    prerender: {
        enabled: true,
        crawlLinks: true
    },
}),
Describe the bug

This bug is related to the "bun" preset.

It generates this code (in the require_react_dom_server_bun_production function):

var stream = new ReadableStream({
    type: "direct",
    pull: function(controller) {
        if (13 === request.status) request.status = 14, closeWithError(controller, request.fatalError);
        else if (14 !== request.status && null === request.destination) {
            request.destination = controller;
            try {
                flushCompletedQueues(request, controller);
            } catch (error) {
                logRecoverableError(request, error, {}), fatalError(request, error);
            }
        }
    },
    cancel: function(reason) {
        request.destination = null;
        abort(request, reason);
    }
}, {
    highWaterMark: 2048
});

This code then throws this error:

[unhandledRejection] TypeError [ERR_INVALID_ARG_VALUE]: The property 'source.type' is invalid. Received 'direct'
    at new ReadableStream (node:internal/webstreams/readablestream:278:15)
    at file:////apps/web/.output/server/_libs/@tanstack/react-router+%5B...%5D.mjs:9049:18
    at completeShell (file:///apps/web/.output/server/_libs/@tanstack/react-router+%5B...%5D.mjs:8549:3)
    at finishedTask (file:///apps/web/.output/server/_libs/@tanstack/react-router+%5B...%5D.mjs:8581:38)
    at performWork (file:///apps/web/.output/server/_libs/@tanstack/react-router+%5B...%5D.mjs:8650:286)
    at file:///apps/web/.output/server/_libs/@tanstack/react-router+%5B...%5D.mjs:8994:11
    at node:internal/process/task_queues:150:7
    at AsyncResource.runInAsyncScope (node:async_hooks:227:14)
    at AsyncResource.runMicrotask (node:internal/process/task_queues:147:8) {
  code: 'ERR_INVALID_ARG_VALUE'
}

This is an LLM explanation, since I am not familiar with runtime differences.

What is happening:

During prerendering, the bundler (Vite/Nitro) resolves the "edge" build of React DOM Server (react-dom/server.edge.js).
React 19 uses an undocumented Cloudflare Workers extension for web streams called "Direct Readable Streams". It explicitly tries to create a stream using new ReadableStream({ type: 'direct' }) to optimize stream pushing.
Node.js and Bun's standard ReadableStream implementations strictly follow the web spec. According to the standard, type can only be "bytes" (or undefined). When the Bun environment sees "direct", it throws the ERR_INVALID_ARG_VALUE error.

When i change the preset to "node" and try to build this, I do not get this error.

Additional context

No response

Logs
╭───────── [Build Info] ───────────╮
 │                                  │
 │  - Build Directory: .output      │
 │  - Date: 5/11/2026, 11:10:53 AM  │
 │  - Nitro Version: 3.0.1-alpha.2  │
 │  - Nitro Preset: bun             │
 │                                  │
 ╰──────────────────────────────────╯

ℹ Spawning preview server...                                                                                                                                                                 11:10:53 AM
ℹ bun run ./server/index.mjs                                                                                                                                                                 11:10:53 AM

➜ Listening on: http://localhost:44407/ (all interfaces)
Port 3000 is in use, trying another one...
Port 3001 is in use, trying another one...
Port 3002 is in use, trying another one...
[prerender] Prerendering pages...
[prerender] Concurrency: 8
[prerender] Crawling: /
[prerender] Crawling: /contact
[prerender] Crawling: /privacy-policy
[prerender] Crawling: /projects
[prerender] Crawling: /schedule
[prerender] Crawling: /diagnostic/completed
[prerender] Crawling: /cases/
[prerender] Crawling: /diagnostic/

Above is the working version (last alpha release)

This is the later versions:


 ╭────────── [Build Info] ────────────╮
 │                                    │
 │  - Build Directory: .output        │
 │  - Date: 5/11/2026, 11:16:15 AM    │
 │  - Nitro Version: 3.0.260429-beta  │
 │  - Nitro Preset: bun               │
 │                                    │
 ╰────────────────────────────────────╯

Port 3000 is in use, trying another one...
Port 3001 is in use, trying another one...
Port 3002 is in use, trying another one...
[prerender] Prerendering pages...
[prerender] Concurrency: 8
[prerender] Crawling: /
[prerender] Crawling: /contact
[prerender] Crawling: /privacy-policy
[prerender] Crawling: /projects
[prerender] Crawling: /schedule
[prerender] Crawling: /diagnostic/completed
[prerender] Crawling: /cases/
[prerender] Crawling: /diagnostic/
TypeError [ERR_INVALID_ARG_VALUE]: The property 'source.type' is invalid. Received 'direct'
    at new ReadableStream (node:internal/webstreams/readablestream:278:15)
    at file:///workspaces/codus/apps/web/.output/server/_libs/@tanstack/react-router+%5B...%5D.mjs:9049:18
    at completeShell (file:///workspaces/codus/apps/web/.output/server/_libs/@tanstack/react-router+%5B...%5D.mjs:8549:3)
    at finishedTask (file:///workspaces/codus/apps/web/.output/server/_libs/@tanstack/react-router+%5B...%5D.mjs:8581:38)
    at performWork (file:///workspaces/codus/apps/web/.output/server/_libs/@tanstack/react-router+%5B...%5D.mjs:8650:286)
    at file:///workspaces/codus/apps/web/.output/server/_libs/@tanstack/react-router+%5B...%5D.mjs:8994:11
    at node:internal/process/task_queues:150:7
    at AsyncResource.runInAsyncScope (node:async_hooks:227:14)
    at AsyncResource.runMicrotask (node:internal/process/task_queues:147:8) {
  code: 'ERR_INVALID_ARG_VALUE'
}
Lingua principale
TypeScript
Stelle
11.5k
Fork
968
Merge medio
4g 9h
PR unite (30g)
64

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nitrojs/nitro

Tutte le issue di nitrojs/nitro

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.