[Bug]: rsbuild build command does not exit when ran inside docker using bun.
System Info
Docker images tested: fedora:latest, oven/bun:1, oven/bun:debian, oven/bun:alpine. All on linux/amd64.
Details
When running bun run build which invokes rsbuild build, the project (a TypeScript React app created with bun create rsbuild@latest) is built correctly but the process does not exit and is stuck at the following forever:
=> => # dist/static/js/index.8b25dab0.js 24.8 kB 7.9 kB
=> => # dist/static/js/lib-polyfill.84abecef.js 40.5 kB 12.4 kB
=> => # dist/static/js/lib-react.0b11da2f.js 140.3 kB 45.0 kB
=> => # dist/static/js/877.f4d2276a.js 325.1 kB 99.5 kB
=> => # Total size: 556.0 kB
=> => # Gzipped size: 174.2 kB
This only occurs when the command is executed within a docker container and works fine outside of docker. I will also report this at bun as I am not sure who's the one responsible for a fix.
Workaround
Currently I just send the command to the background and add a generous sleep like this:
RUN bun run build &
RUN sleep 10
Reproduce link
No response
Reproduce Steps
- Create Rspack project with
bun create rsbuild@latest. - Create following Dockerfile:
FROM oven/bun:alpine as webinterface-builder
COPY rspack-project /app/rspack-project
WORKDIR /app/rspack-project
RUN bun install
RUN bun run build
CMD ["echo 'never reached'"]
- Run
docker build -t my-container . - Observe that the project is build correctly but the container creation is stuck after
bun run buildand "never reached" is never printed.
If your environment has node.js installed, bun run build will run rsbuild with node.js instead of bun itself as there's a shebang refer to node in rsbuild's cli. that's why it works outside the docker.
a smaller reproduce
const rspack = require('@rspack/core');
rspack({ mode: 'none' }).run((err) => console.log({err}));
running it via bun, the process will keep running after internally called instance.build(), even outside docker.
How to escape
rspack
// rspack.config.js
module.exports = {
plugins: [
{
apply(compiler) {
compiler.hooks.done.tap("quit", () => {
if (typeof Bun !== 'undefined') {
process.exit(process.exitCode || 0);
})
});
},
},
],
};
rsbuild
export default defineConfig({
// ...
plugins: [
{
setup: (api) => {
api.onAfterBuild(({ isFirstCompile, stats }) => {
if (typeof Bun !== 'undefined') {
process.exit(process.exitCode || 0);
}
});
},
},
],
// ...
})
@xc2 seems bun's compatible issue?
@xc2 seems bun's compatible issue?
@hardfist yes, seems like bun's napi implementation problem. still not find out the rspack code that causes bun hanging
If your environment has node.js installed,
bun run buildwill run rsbuild with node.js instead of bun itself as there's a shebang refer to node in rsbuild's cli. that's why it works outside the docker.a smaller reproduce
const rspack = require('@rspack/core'); rspack({ mode: 'none' }).run((err) => console.log({err}));running it via bun, the process will keep running after internally called
instance.build(), even outside docker.How to escape
rspack
// rspack.config.js module.exports = { plugins: [ { apply(compiler) { compiler.hooks.done.tap("quit", () => { if (typeof Bun !== 'undefined') { process.exit(process.exitCode || 0); }) }); }, }, ], };rsbuild
export default defineConfig({ // ... plugins: [ { setup: (api) => { api.onAfterBuild(({ isFirstCompile, stats }) => { if (typeof Bun !== 'undefined') { process.exit(process.exitCode || 0); } }); }, }, ], // ... })
Thank you! Installing nodejs with alpine package manager fixed this issue. Cheers!:)
close since seem this issue is fixed