Open seepine opened 3 months ago
Darwin 23.5.0 arm64 arm Bun v1.1.10
❯ bun build --compile ./index.ts --outfile dist/app
[28ms] bundle 287 modules
[109ms] compile dist/app
❯ ./dist/app
Server listening on http://[::1]:51781
[2024-05-28 13:51:53.838 -0700] INFO: Server listening at http://[::1]:51781
[2024-05-28 13:51:53.841 -0700] INFO: Server listening at http://127.0.0.1:51781
Darwin 23.5.0 arm64 arm Bun v1.1.10
❯ bun build --compile ./index.ts --outfile dist/app [28ms] bundle 287 modules [109ms] compile dist/app ❯ ./dist/app Server listening on http://[::1]:51781 [2024-05-28 13:51:53.838 -0700] INFO: Server listening at http://[::1]:51781 [2024-05-28 13:51:53.841 -0700] INFO: Server listening at http://127.0.0.1:51781
Hi, maybe you need to clean up the environment, such as packaging binary files in Dockerfile
FROM seepine/alpine:glibc-3.18
WORKDIR /workspace
COPY ./dist/app /workspace/app
ENTRYPOINT ./app
@sirenkovladd's example only works because the bundle has hardcoded paths to files in the local environment, but they won't be resolved in docker or another machine.
The answer to the question that was asked is to import or require the module somewhere in the code. You could do this, for example:
const transports = {
pretty: require('pino-pretty'),
file: require('pino/file'),
otlp: require('pino-opentelemetry-transport'),
};
The real issue is that some Pino runtime dependencies are not getting bundled because they're used in worker threads. It requires a bundler plugin to make it work. Info about this here: https://github.com/pinojs/pino/blob/main/docs/bundling.md
Edit: I've created a bun plugin for Pino (does not handle --compile though): https://github.com/vktrl/bun-plugin-pino
Discussed in https://github.com/oven-sh/bun/discussions/11019