Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
m4r1vs opened this issue Jul 7, 2024 · 4 comments
Open
Labels
bug Something isn't working

Comments

@m4r1vs
Copy link

m4r1vs commented Jul 7, 2024

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 m4r1vs added bug Something isn't working pending triage The issue/PR is currently untouched. labels Jul 7, 2024
@xc2
Copy link
Collaborator

xc2 commented Jul 8, 2024

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
Copy link
Contributor

hardfist commented Jul 8, 2024

@xc2 seems bun's compatible issue?

@xc2
Copy link
Collaborator

xc2 commented Jul 8, 2024

@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
Copy link
Author

m4r1vs commented Jul 8, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants