Repository navigation
fix(dev): probe ports through the real Deno runtime, not the dnt shim - #3610
Conversation
`veryfront dev` died immediately under a globally installed CLI (`deno install -gArf npm:veryfront`) with an unclassified error: [unknown-error] Unknown/unclassified error Detail: Cannot read properties of null (reading 'fd') `isPortAvailable` branched on `isDeno` and then called `Deno.listen`. dnt rewrites every bare `Deno.` call site in the published npm package into `@deno/shim-deno`, whose Node-backed `listen()` reads `server._handle.fd` - null under Deno's `node:net`. So on a Deno-global install the runtime check saw a real Deno and passed, while the call itself reached the shim and threw a `TypeError` the error registry cannot classify. `build`, `serve`, `routes` and `doctor` were unaffected because only `dev` probes ports this way. Read the runtime with `getDenoRuntime()` instead - the accessor that exists for exactly this. It resolves the real global through `Reflect.get`, which dnt leaves alone. Under Node it returns undefined and the existing `node:net` path still runs. Deno and the shim are the same object in-repo, so the regression test asserts the invariant over the source dnt actually rewrites.
|
Warning Review limit reached
Next review available in: 44 seconds Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Comment |
Symptom
A CLI installed the way the installation guide now tells people to install it —
deno install -gArf npm:veryfront(added by 0d36976 / #3569) — produces aworking
veryfront, butveryfront devdies before printing a URL:build,serve,routesanddoctorall succeed under the same install. Thenpm-global install of the identical version (
npm i -g veryfront@0.1.1229) runsdevfine, so the defect is specific to running the published package on Deno.Root cause
Recovered by unwrapping the boundary error against published
0.1.1229:isPortAvailablebranched onisDenoand then calledDeno.listen. dntrewrites every bare
Deno.call site in the published npm package into@deno/shim-deno— the emitted line really isdntShim.Deno.listen(...)— andthat shim's Node-backed
listen()readsserver._handle.fd, which is nullunder Deno's
node:net.The two halves therefore disagreed on a Deno-global install:
isDenois computed from the real global (Reflect.get(globalThis, "Deno")),so it was
true;Denoidentifier in the same function had been rewritten to the shim.runtime.tseven documentsisDenoas "true if running in the real Deno runtimerather than a dnt shim" — the constant was right, the call site was not. The
resulting
TypeErrorcarries nothing the error registry can match, which is whythe user got
unknown-errorrather than anything actionable.port-fallback.jswas the onlydntShim.Denoreference in the wholedevcommand tree, which is exactly why only
devwas affected.Fix
Read the runtime with
getDenoRuntime()— the accessor that already exists forthis, used the same way in
cli/commands/serve/split-mode.tsand elsewhere. Itresolves the real global through
Reflect.get, which dnt leaves alone. UnderNode it returns
undefinedand the existingnode:netpath still runs.Regression test
Deno and the shim are the same object in-repo, so no in-process test can tell
Deno.listenfromgetDenoRuntime().listenhere — the divergence only exists inthe dnt output. The test therefore asserts the invariant over the source dnt
actually rewrites: comment- and string-stripped
port-fallback.tsmust containno bare
Deno.call site, and must reach the runtime viagetDenoRuntime().Verified red before the fix, for the right reason (1 offender:
Deno.listen),and green after.
Verified against the published repro
Reproduced first against published
0.1.1229outside the platform checkout:Then re-ran the finding's own command with only this change applied to the
published artifact's emitted
port-fallback.js:Notes
No doc change is needed here; the installation guide's
deno install -gArf npm:veryfrontinstruction is correct and this makes it true fordevtoo.Separately, #3569 is merged but the live installation page still does not show
the Deno section — that deployment gap is tracked by another finding, not this PR.