nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Build file with bun preset crashes when using SSE

Open BuddiesTV opened this issue 2 months ago • 1 comments

Environment

nitropack: 2.12.8 bun: 1.3.1

Reproduction

Commands:

bun init Select a project template: Library bun add nitropack

Files: Delete index.ts

Create nitro.config.ts:

export default defineNitroConfig({
    preset: "bun",
});

Create routes/index.ts:

export default defineEventHandler(() => {
    return `
    <!DOCTYPE html>
    <html>
      <head>
        <title>Nitro SSE Demo</title>
      </head>
      <body>
        <script>
          new EventSource('/events');
        </script>
      </body>
    </html>
  `;
});

Create routes/events.ts:

export default defineEventHandler(async (event) => {
    const eventStream = createEventStream(event);

    const interval = setInterval(async () => {
        await eventStream.push(`Message @ ${new Date().toLocaleTimeString()}`);
    }, 1000);

    eventStream.onClosed(async () => {
        clearInterval(interval);
        await eventStream.close();
    });

    return eventStream.send();
});

Commands:

bunx nitro build bun run .output/server/index.mjs

Visit: http://localhost:3000/

Look into the console:

error: undefined
undefined
error: undefined
undefined

Describe the bug

When using Nitro's SSE feature & bun, it crashes. Works in dev mode, only applied to the builded .mjs file. Also works when using node instead of bun.

Additional context

Sometimes works, when then reloading the page or re-open it, it crashes.

Logs

error: undefined
undefined
error: undefined
undefined

BuddiesTV avatar Oct 24 '25 13:10 BuddiesTV

This is more likely Buns issue

kricsleo avatar Oct 25 '25 15:10 kricsleo