Skip to content

App crashes on startup when bundled #61

Description

@MoeDevelops

What version of Elysia is running?

1.4.28

What version of Node Adapter are you using?

1.4.6

What platform is your computer?

Linux 7.0.10-201.fc44.x86_64

What steps can reproduce the bug?

Bundle the elysia app with the node adapter.
Try to run the bundle output.

I made an example repository with 3 different bundlers: bun, esbuild and rolldown.
https://github.com/MoeDevelops/elysia-node-error

I also made a github action and dockerfiles, to make sure its not just on my machine.
https://github.com/MoeDevelops/elysia-node-error/actions/runs/26818126805

The index.ts:

import node from "@elysia/node";
import Elysia from "elysia";

const PORT = 3000

const app = new Elysia({ adapter: node() }).get("/", () => "Hello, World!")
app.listen(PORT)

console.log(`Listening on http://localhost:${PORT}`)

What is the expected behavior?

Using the example repo

npm run start

> start
> node index.ts

Listening on http://localhost:3000

What do you see instead?

Using the example repo with rolldown, but happens with the other bundlers aswell.

npm run build:rolldown && node build/rolldown.js 

> build:rolldown
> rolldown -c

<DIR>/rolldown.js  chunk │ size: 731.57 kB                                                                                                                                                                            
                                                                                                                                                                                                                      
✔ rolldown v1.0.3 Finished in 81.91 ms                                                                                                                                                                               
[crossws] Using SSE adapter for WebSocket support. This requires a custom WebSocket client (https://crossws.h3.dev/adapters/sse).
file:///home/moe/Development/elysia-node-error/build/rolldown.js:18391
                                const hostname = server.serveOptions.host ?? "localhost";
                                                                     ^

TypeError: Cannot read properties of undefined (reading 'host')
    at file:///home/moe/Development/elysia-node-error/build/rolldown.js:18391:42
    at _Elysia.listen (file:///home/moe/Development/elysia-node-error/build/rolldown.js:16549:70)
    at file:///home/moe/Development/elysia-node-error/build/rolldown.js:18455:74
    at ModuleJob.run (node:internal/modules/esm/module_job:430:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:661:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)

Node.js v24.14.0

The lines of code in elysia:

let server = serve(serverOptions);
const nodeServer = server.node?.server;
const hostname = server.serveOptions.host ?? "localhost"; // <- Error happens here
const port = server.options.port;

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

Yes (package-lock.json in this case)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions