oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.88k stars 2.74k forks source link

Inconsistent bundling behavior between local machine and Docker container #14551

Open erik-balfe opened 1 week ago

erik-balfe commented 1 week ago

What version of Bun is running?

1.1.30

What platform is your computer?

Ubuntu 20.4 and docker image "oven/bun:1.1.30"

What steps can reproduce the bug?

  1. Set up a project using llamaindex and other dependencies (full package.json available if needed, but currently llamaindex is enough for reproducing the error).
  2. Create a build script (build.ts) that uses bun build with the following options:
      bun build MAIN_FILE --compile --minify --sourcemap --target bun --format esm --outfile OUTPUT_FILE
  3. Build the project locally using bun run build.
  4. Create a Dockerfile:
      FROM oven/bun:1.1.30
      WORKDIR /app
      COPY package.json bun.lockb* ./
      RUN bun install --frozen-lockfile
      COPY src/ ./src/
      COPY tsconfig.json ./
      COPY build.ts ./
      CMD ["bun", "run", "build"]
  5. Build the Docker image and run it to produce the executable.
  6. Compare the two executables (size, hash, and functionality).

What is the expected behavior?

The Docker-built executable should have the same size and functionality as the locally-built executable.

What do you see instead?

Additional information

tsconfig in the project (if it makes sense)

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "noEmit": true,
    "allowJs": true,
    "ignoreDeprecations": "5.0",
    "isolatedModules": true,
    "resolveJsonModule": true,
    "forceConsistentCasingInFileNames": true,
    "strict": false,
    "strictNullChecks": true,
    "allowSyntheticDefaultImports": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

Questions:

  1. Why is the bundler producing different outputs in these two environments despite using the same Bun version and lock file?
  2. Is there a known issue with how Bun handles WebAssembly files (like tiktoken_bg.wasm) during the bundling process in containerized environments?
  3. Are there any additional flags or configurations that should be used to ensure consistent bundling behavior across different environments?

Id be happy to provide any additional info about the bug if needed.

erik-balfe commented 5 days ago

I believe this issue is specifically related to wasm dependencies, as I have only encountered it with wasm packages in the error messages, and not with any others.

I face this problem on one of my machines very rarely when launching the same binary built with Bun. Most of the time, it works well. However, in all other environments (GitHub Actions, Docker, and other Linux machines), it occurs every time, despite using the exact same binary everywhere.