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

fix: make rsbuild listen on a random port #47

Merged
merged 1 commit into from
Jul 17, 2024
Merged

fix: make rsbuild listen on a random port #47

merged 1 commit into from
Jul 17, 2024

Conversation

tmkx
Copy link
Contributor

@tmkx tmkx commented Jul 17, 2024

close #23
close #32

@fi3ework
Copy link
Member

fi3ework commented Jul 17, 2024

Great work! I am wondering should Rsbuild listen to a port in middleware mode? If so, what's the purpose? 🤔 Could @chenjiahan give some guidance.

@chenjiahan
Copy link
Member

Rsbuild server should not listen to any port in the middleware mode, @9aoy can you check this

@fi3ework
Copy link
Member

I'm merging the PR now, we could improve the default behavior in Rsbuild after @9aoy checks the code. Thanks @tmkx!

@fi3ework fi3ework merged commit 94b5335 into rspack-contrib:main Jul 17, 2024
2 checks passed
@tmkx tmkx deleted the fix/port-conflict branch July 17, 2024 09:39
htmlFallback: false,
strictPort: true,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This problem is caused by configuring strictPort: true. Rsbuild will parse the configuration (including calculating available port) when the server is initialized. When the port is occupied and strictPort is configured, an error will be reported.

image

https://github.com/web-infra-dev/rsbuild/blob/v0.7.9/packages/core/src/server/helper.ts#L219-L224

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, I'll remove port setting.

@matheusmichels
Copy link

Hey @fi3ework, this fixed the "occupied port" issue when running Storybook from a container/remote environment. However, the HMR stopped working cause now Storybook doesn't know the dev server port.

@tmkx
Copy link
Contributor Author

tmkx commented Jul 26, 2024

rsbuild will listen to another port due to a port conflict, but hmr still works because the rsbuild dev middleware can accept connections through the Storybook server

router.use(rsbuildServer.middlewares)

for a speedy verification, you can follow the instructions to confirm if it functions in a container environment:

FROM ubuntu:latest

ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
ENV NVM_DIR=/root/.nvm

ADD https://github.com/rspack-contrib/storybook-rsbuild.git /app

WORKDIR /app

RUN apt-get update && apt-get install -y curl && \
  curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash && \
  . ~/.bashrc && nvm install && \
  corepack enable && pnpm i && pnpm build

EXPOSE 6006
CMD [ "bash", "-c", ". /root/.nvm/nvm.sh && pnpm -C sandboxes/react-18 exec storybook dev --no-open -p 6006" ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not working on Linux Error: Port is occupied when starting from container
5 participants