I’m looking for help defining a Dockerfile for Bun apps defined with a workspaces / monorepo file structure.
I have an existing application that is working with pnpm workspaces, but am considering using Bun for the websocket runtime, test runner and general performance improvement.
The Sveltekit is happily running on Bun locally, but I am having difficulty building the app for production in a container.
The repo takes this structure:
├── packages
│ ├── blob
│ ├── db
│ ├── logging
│ ├── permissions
│ └── storage
├── sites
│ ├── frontend
│ │ ├── src
│ │ ├── Dockerfile
│ │ ├── package.json
│ │ ├── svelte.config.js
│ │ ├── tsconfig.json
│ │ └── vite.config.ts
│ └── socket
│ ├── src
│ ├── Dockerfile
│ ├── package.json
│ └── tsconfig.json
├── bunfig.toml # previously pnpm-workspace.yaml
├── bun.lockb # previously pnpm-lock.yaml
├── package.json
└── tsconfig.json
The package.json
in the workspace root looks like this:
{
"workspaces": [
"packages/*",
"sites/*",
],
"scripts": {
"build": "cd sites/frontend && bun run build"
}
// ... etc
}
And the package.json
in sites/frontend
looks like this
{
"workspaces": [
"packages/*",
"sites/*",
],
"scripts": {
"dev": "vite dev",
"build": "vite build"
},
"devDependencies": {
"@packages/db": "workspace:*",
"@packages/storage": "workspace:*",
// ...
}
}
I have tried & modified various Dockerfile templates – eg. following the docs, modifying my existing Dockerfile based on pnpm, and running Fly.io’s Dockerfile generator (which I am currently using).
From the workspace root, I then instruct Docker to build with:
docker build -f sites/frontend/Dockerfile --build-arg NPM_TOKEN="*****" .
But fails at RUN bun install
with:
bun install v1.1.10 (5102a944)
error: Module not found "/app/node_modules/@sites/frontend/node_modules/.bin/../@sveltejs/kit/svelte-kit.js"
Bun v1.1.10 (Linux x64 baseline)
Have also run into a similar error for Vite with previous Dockerfile configurations:
error: Module not found
/app/node_modules/@sites/frontend/node_modules/.bin/../vite/bin/vite.js
Running the same steps in the Dockerfile manually in the terminal always succeeds.
Would appreciate any troubleshooting guidance, links to real world examples in the wild, or known foot-guns that could be preventing this from working.
Thanks ♥