Build file with bun preset crashes when using SSE
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with nitro.config.ts, routes/index.ts, routes/events.ts, and the commands bunx nitro build followed by bun run .output/server/index.mjs. Compare the built .output/server/index.mjs with dev mode and the Node runtime, then trace Bun preset handling around the SSE event stream; done means the built Bun server serves /events reliably without the logged errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bun, typescript
- Domain
- backend, build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100