Migrate dev server to webpack-dev-server v5 (rc.4) - #224
Merged
Merged
Conversation
RunWebpackDevServerStrategy still used the webpack-dev-server v3 API:
`new WebpackDevServer(compiler, options)` plus `server.listen(port, host, cb)`.
v4 tolerated the old argument order through a deprecated compatibility shim,
but v5 removed it, so the compiler was validated as an options object and any
consumer on v5 failed with:
Invalid options object. Dev Server has been initialized using an options
object that does not match the API schema.
- options has an unknown property '_assetEmittingPreviousFiles'.
Switch to the v5 API: options first and compiler second, port/host folded into
those options (v5 reads them from there rather than from listen() arguments),
and start()/stop() instead of listen()/close().
Bump webpack-dev-server to ^5.2.6, which also carries the fixes for
GHSA CSRF-via-internal-dev-endpoints and DoS-via-malformed-Host/Origin
(both <= 5.2.5). Consumers pinning wds 5 through an `overrides` entry to get
those fixes no longer need it.
TypeScript goes ^4.3.4 -> ^4.9.5 because this is required, not cosmetic:
webpack-dev-server 5 references `import("open").Options` in its types, and
open@10 declares `import {type ChildProcess}` — inline type modifiers need
TS >= 4.5, and `skipLibCheck` does not suppress syntax errors in .d.ts files.
Drop @types/webpack-dev-server: it is now a deprecated stub, since
webpack-dev-server ships its own type definitions.
Note for consumers: webpack-dev-server v5 removed `onBeforeSetupMiddleware`.
Projects using it must move to `setupMiddlewares`, registering their routes on
`devServer.app` inside the callback — that callback runs before the dev server
applies its own middleware stack, so route precedence over historyApiFallback
is preserved.
Verified: tsc build clean, 2 test suites / 19 tests pass, and a consumer
(peo-frontend) starts the dev server successfully with endpoints served ahead
of the SPA fallback.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
RunWebpackDevServerStrategystill used the webpack-dev-server v3 API —new WebpackDevServer(compiler, options)andserver.listen(port, host, cb).v4 tolerated the old argument order behind a deprecated compatibility shim (it logged
DEP_WEBPACK_DEV_SERVER_CONSTRUCTOR). v5 removed that shim, so the compiler gets validated as an options object and any consumer on wds 5 dies at startup:(
_assetEmittingPreviousFilesis an internal webpackCompilerfield — the tell-tale sign of the swapped arguments.)This surfaced in
peo-frontend, which pins wds 5 via anoverridesentry to pick up two dev-server security fixes, and consequently had a brokennpm startfor ~2.5 months.What
run-webpack-dev-server.ts→ v5 API: options first, compiler second;port/hostfolded into those options (v5 reads them from there, not fromlisten()arguments);start()/stop()replacinglisten()/close().webpack-dev-server^4.11.1→^5.2.6. 5.2.6 carries the fixes for the CSRF-via-internal-dev-endpoints and DoS-via-malformed-Host/Origin advisories (both affect<= 5.2.5). Consumers currently forcing wds 5 throughoverridesto get those can drop the override once they're on this ffbt.typescript^4.3.4→^4.9.5— required, not housekeeping. wds 5's types referenceimport("open").Options, andopen@10declaresimport {type ChildProcess} from 'node:child_process'. Inline type modifiers need TS ≥ 4.5, andskipLibCheckdoes not suppress syntax errors in.d.tsfiles, so the build fails on TS 4.3 withopen/index.d.ts(1,14): error TS1005.@types/webpack-dev-server— now a deprecated stub, since wds ships its own types. Removing it also avoids v4 types shadowing v5's.1.0.0-rc.4.onBeforeSetupMiddlewarewds v5 removed
onBeforeSetupMiddleware. Any project passing it viadevServerConfigwill fail schema validation after upgrading. The migration issetupMiddlewares:Registering routes directly on
devServer.appinside the callback preserves the old ordering: wds invokessetupMiddlewaresbefore it applies its own middleware array, so consumer routes keep precedence overhistoryApiFallback. Worth calling out in the release notes for rc.4 —peo-frontendneeds exactly this change.Verification
npm run build(tsc)npm run test:cipeo-frontend)npm startboots on :9095, no schema error, webpack compiled successfully/dev-api/documents→application/json(real payload),/api/v2/edit/setDates→text/plain OK— handled by the app's routes, not swallowed by the SPA fallbackpeo-frontendsrc/compiles with 0 errorsConsumer testing was done by
npm pack-ing this branch and installing the tarball intopeo-frontend.Note
npm installon this repo needs--legacy-peer-depson modern npm — pre-existing and unrelated: the root wantstslint ^6.0.0whiletslint-config-airbnb@5.11.2peer-requirestslint ^5.11.0. Untouched here.🤖 Generated with Claude Code