Stencil devServer port and openBrowser fail-fast behavior
0 reputation · 14 Aug 2022, 17:20 UTC
0 reputation · 14 Aug 2022, 17:20 UTC
Goal: Configure Stencil's development server so that a port conflict or missing browser produces a hard failure instead of a warning or silent continuation in headless CI.
The stencil.config.ts devServer block accepts port and openBrowser, but the public contract does not document a stable exit code, automatic alternative-port fallback, or a strict browser-launch requirement. When the port is bound, Node's HTTP server can raise EADDRINUSE; when openBrowser is enabled without a graphical session, behavior varies by operating system and Stencil release.
Unresolved: whether the dev server should exit immediately on EADDRINUSE, whether openBrowser: true should fail hard on headless hosts, and what configuration surface controls that boundary.
Does Stencil expose a configuration option to force a non-zero exit when devServer.port is already occupied? Should openBrowser: true be treated as a hard failure in headless CI, or only as a warning? Is there a documented version range in which port-conflict exit codes are stable enough for automation?
33775 reputation · 14 Aug 2022, 19:31 UTC
Stencil does not expose a specific configuration option to toggle "fail-fast" mode for port conflicts or browser launch failures. The behavior is tied to the underlying Node.js HTTP server and the open package, meaning there is no stable, documented API to force a non-zero exit code specifically for EADDRINUSE across all versions.
When devServer.port is already occupied, Node.js typically throws an EADDRINUSE error. In most Stencil releases, this results in a non-zero exit code, but this is a side effect of the process crashing rather than a managed configuration feature. Because some versions may handle this differently or log a warning before exiting, you cannot rely on a consistent exit code for automation across different Stencil version ranges.
Setting openBrowser: true in a headless CI environment should not be treated as a hard failure mechanism. Depending on the operating system and the version of the open utility used by Stencil, the result will vary between a logged warning and a silent failure. It does not reliably produce a non-zero exit code that can be used to trigger a CI build failure.
To ensure a stable, fail-fast environment in headless CI, avoid relying on Stencil's internal server logic for environment validation. Instead, use the following strategy:
openBrowser: false in stencil.config.ts or via environment overrides to prevent unpredictable OS-level errors.# Example: Fail-fast port check before running stencil dev
if lsof -Pi :35729 -sTCP:LISTEN -t >/dev/null ; then
echo "Error: Port 35729 is already in use"
exit 1
fi
npm run start
To confirm the behavior of your specific Stencil version, perform these tests:
nc -l 35729) and run npm run start. Check the exit code using echo $?.openBrowser: true and verify if the process remains running despite the lack of a browser.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.