Why does transpiling with ESBuild won’t work with my express + ejs app?

I have the following file structure

.
├── package.json
├── public
│   ├── fonts
│   │   └── AppleColorEmoji.ttf
│   └── images
│       ├── favicon.ico
│       └── ico.svg
├── src
│   ├── application.js
│   ├── controllers
│   │   ├── event.controller.js
│   │   └── user.controller.js
│   ├── database.js
│   ├── index.js
│   ├── middlewares
│   │   ├── auth.middleware.js
│   │   └── error.middleware.js
│   ├── models
│   │   ├── event.model.js
│   │   ├── token.model.js
│   │   └── user.model.js
│   ├── routers
│   │   ├── index.js
│   │   └── user.router.js
│   ├── services
│   │   ├── auth.service.js
│   │   └── event.service.js
│   └── views
│       ├── pages
│       │   ├── 404.ejs
│       │   ├── events.ejs
│       │   ├── index.ejs
│       │   ├── login.ejs
│       │   └── submit.ejs
│       └── partials
│           ├── footer.ejs
│           ├── head.ejs
│           └── header.ejs
└── yarn.lock

and tried to use esbuild to ship this application (express + ejs) with the following command in package.json

...
"build": "esbuild src/index.js --platform=node --bundle --minify --outfile=dist/index.js",
...

this produces a single file index.js in a dist folder. The program runs but when I make any operacion to see the views. It throws a 500 http status. Do you guys know how to solve this issue?