Skip to content

fix: assign distinct ports to dev servers sharing devServer options - #4886

Merged
alexander-akait merged 2 commits into
mainfrom
fix/multi-dev-server-ports
Oct 30, 2026
Merged

alexander-akait merged 2 commits into
mainfrom
fix/multi-dev-server-ports

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #4847 and #4885. Fixes #2408 for webpack-dev-server 6.

Shared devServer options

Multi-configurations often share one devServer object between configurations. The automatic port of the first dev server was written to that shared object, so every other dev server got the same port and failed with EADDRINUSE. The CLI now copies the options for each configuration.

Test for multiple dev servers without ports

The test for #2408 ("should work in multi compiler mode with multiple dev servers") was skipped. It now runs with webpack-dev-server 6:

  • configurations without ports share one devServer object;
  • each dev server must get a distinct port;
  • every dev server must serve the bundles of all compilers.

Its config imported the shared options with const { devServerConfig } = require(...), but the helper exports the object itself, so devServer was undefined. Other configs import it the same way; they are left unchanged to keep their snapshots.

The test fails without the fix and passes with it.

Free ports in the new serve tests

The serve tests added in #4847 (automatic-ports, error-handling, per-compiler, rebuild) now use getFreePort from #4885. Before, they took ports from the ephemeral range, where other connections can take them before the dev server listens. getFreePort accepts ports to exclude, as the per-compiler test needs two.


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Development servers using shared configuration now receive distinct ports, allowing multiple servers to run without explicit port assignments.
  • Tests
    • Added coverage for serving multiple compilers on separate ports. Multi-server coverage is skipped for webpack-dev-server 5.

Ports from the OS can be taken by other connections before the dev server
listens, the helper takes them from a range of the Jest worker.

Claude-Session: https://claude.ai/code/session_013FhutRFjuQemBzekJMYcqL
Configurations can share one devServer object, the port assigned to the
first dev server was written to it and reused by the others. Enable the
test for multiple dev servers without ports.

Claude-Session: https://claude.ai/code/session_013FhutRFjuQemBzekJMYcqL
@changeset-bot

changeset-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c0cf560

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

This PR is packaged and the instant preview is available (d4ee8bd).

Install it locally:

  • npm
npm i -D create-webpack-app@https://pkg.pr.new/create-webpack-app@d4ee8bd webpack-cli@https://pkg.pr.new/webpack-cli@d4ee8bd
  • yarn
yarn add -D create-webpack-app@https://pkg.pr.new/create-webpack-app@d4ee8bd webpack-cli@https://pkg.pr.new/webpack-cli@d4ee8bd
  • pnpm
pnpm add -D create-webpack-app@https://pkg.pr.new/create-webpack-app@d4ee8bd webpack-cli@https://pkg.pr.new/webpack-cli@d4ee8bd

@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.08%. Comparing base (9bcb6d5) to head (c0cf560).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4886   +/-   ##
=======================================
  Coverage   95.07%   95.08%           
=======================================
  Files          14       14           
  Lines        5873     5874    +1     
  Branches      895      894    -1     
=======================================
+ Hits         5584     5585    +1     
  Misses        288      288           
  Partials        1        1           
Files with missing lines Coverage Δ
packages/webpack-cli/src/webpack-cli.ts 96.95% <100.00%> (+<0.01%) ⬆️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9bcb6d5...c0cf560. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0521231b-70c7-4074-885e-a5c6fd995525
Commits

Reviewing files that changed from the base of the PR and between 9bcb6d5 and c0cf560.

Files selected for processing: 9
  • .changeset/shared-dev-server-options.md
  • packages/webpack-cli/src/webpack-cli.ts
  • test/serve/automatic-ports/automatic-ports.test.js
  • test/serve/basic/multi-dev-server.config.js
  • test/serve/basic/serve-basic.test.js
  • test/serve/error-handling/serve-error-handling.test.js
  • test/serve/per-compiler/serve-per-compiler.test.js
  • test/serve/rebuild/serve-rebuild.test.js
  • test/utils/test-utils.js

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Walkthrough

The CLI now shallow-copies supplied devServer options. The multi-server test configuration no longer sets separate ports. The updated test checks that two servers receive distinct ports and return successful responses for both compiler outputs. The shared getFreePort test utility now accepts excluded ports, and several serve tests use it instead of dynamically importing get-port.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Minimal · up to c0cf5

No merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Linked Issues check Warning Issue #2408 requires webpack serve to serve multiple configurations with unique publicPath values from the same port. The PR instead copies each shared devServer options object and tests that th… Implement the #2408 behavior for unique publicPath values: run the configurations from one shared server and add an automated test that verifies one port serves all required bundle paths. If distinct ports are the intended replacement, up…
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main fix: assigning distinct ports to development servers that share devServer options.
Out of Scope Changes check Passed The changed files stay within the multi-server serve scope of #2408. The CLI copy prevents shared options from reusing an automatic port. The basic serve test covers the multi-server case. The `getFre…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Out of Scope Changes check

Explanation

The changed files stay within the multi-server serve scope of #2408. The CLI copy prevents shared options from reusing an automatic port. The basic serve test covers the multi-server case. The getFreePort updates stabilize the related serve tests, and the changeset documents the fix.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 8 files. (1 skipped: 1 unsupported.)

Full details: Linked Issues check

Explanation

Issue #2408 requires webpack serve to serve multiple configurations with unique publicPath values from the same port. The PR instead copies each shared devServer options object and tests that the servers receive two distinct ports (test/serve/basic/serve-basic.test.js). The PR does not implement or verify the same-port behavior required by #2408.

Resolution

Implement the #2408 behavior for unique publicPath values: run the configurations from one shared server and add an automated test that verifies one port serves all required bundle paths. If distinct ports are the intended replacement, update the linked issue requirements before relying on this PR as its fix.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@alexander-akait
alexander-akait merged commit d4ee8bd into main Oct 30, 2026
35 checks passed
@alexander-akait
alexander-akait deleted the fix/multi-dev-server-ports branch October 30, 2026 14:41
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.

serve does not work with multi-server

1 participant