web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
9.07k stars 521 forks source link

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

Closed m4r1vs closed 3 weeks ago

m4r1vs commented 2 months ago

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'"]


3. Run `docker build -t my-container .`
4. Observe that the project is build correctly but the container creation is stuck after `bun run build` and "never reached" is never printed.
xc2 commented 2 months ago

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);            
          }
        });
      },
    },
  ],
  // ...
})
hardfist commented 2 months ago

@xc2 seems bun's compatible issue?

xc2 commented 2 months ago

@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

m4r1vs commented 2 months ago

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!:)

hardfist commented 3 weeks ago

close since seem this issue is fixed