rspack icon indicating copy to clipboard operation
rspack copied to clipboard

[Bug]: rsbuild build command does not exit when ran inside docker using bun.

Open m4r1vs opened this issue 1 year ago • 4 comments

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

  1. Create Rspack project with bun create rsbuild@latest.
  2. 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'"]
  1. Run docker build -t my-container .
  2. Observe that the project is build correctly but the container creation is stuck after bun run build and "never reached" is never printed.

m4r1vs avatar Jul 07 '24 22:07 m4r1vs

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 avatar Jul 08 '24 05:07 xc2

@xc2 seems bun's compatible issue?

hardfist avatar Jul 08 '24 06:07 hardfist

@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

xc2 avatar Jul 08 '24 06:07 xc2

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);            
          }
        });
      },
    },
  ],
  // ...
})

Thank you! Installing nodejs with alpine package manager fixed this issue. Cheers!:)

m4r1vs avatar Jul 08 '24 06:07 m4r1vs

close since seem this issue is fixed

hardfist avatar Aug 13 '24 03:08 hardfist