Repository navigation
feat: better response logging - #16744
Merged
Merged
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/d84cda9deace7d7dd267b04d2418bd60bafa3118Open in |
🦋 Changeset detectedLatest commit: d84cda9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
teemingc
reviewed
Aug 11, 2026
| import process from 'node:process'; | ||
| import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'; | ||
| import { dirname, join } from 'node:path'; | ||
| import { clearLine, moveCursor } from 'node:readline'; |
… `internal.js` can crash non-Node runtimes (Cloudflare Workers, Vercel Edge, Deno) at module load, since this module is bundled into the server shipped to all adapter targets.
This commit fixes the issue reported at packages/kit/src/runtime/server/internal.js:3
## The bug
`log_response` was moved into `packages/kit/src/runtime/server/internal.js`, which is **runtime code**, not build/dev-time code:
- `internal.js` is aliased to `__sveltekit/server` (`packages/kit/src/exports/vite/index.js:441-443`).
- Its exports (including `log_response`) are re-exported by the generated server entry (`packages/kit/src/core/sync/write_server.js:28,81`).
- Therefore `internal.js` is bundled into the server that ships to **all** adapter targets, including non-Node edge runtimes.
The new code added a top-level static import:
```js
import { styleText } from 'node:util';
```
This directly contradicts the deliberate pattern used by the sibling module it re-exports from, `packages/kit/src/runtime/server/sourcemaps.js`, which fetches Node builtins via `globalThis.process?.getBuiltinModule?.('node:...')` with the comment:
> using `getBuiltinModule` rather than `import` makes this safe to run in non-Node-compatible environments
## Failure mode
`log_response` is only ever invoked from Node-only build/dev contexts:
- `packages/kit/src/exports/vite/dev/index.js` (dev server)
- `packages/kit/src/core/postbuild/prerender.js` (prerender)
It is **never** called from the production request handler. But because the function (and its `node:util` import) live in a runtime module that is bundled for every adapter, a static `import ... from 'node:util'` risks surviving into the deployed server bundle. On a runtime that does not provide `node:util` (or lacks the relatively new `styleText`), resolving that import at module load throws and crashes the worker — even though the imported symbol is never used at request time. Whether tree-shaking removes it is bundler/adapter-dependent and not guaranteed, so relying on it is fragile.
## The fix
Replaced the static import with the established `getBuiltinModule` pattern, with a graceful fallback that returns the plain text when `styleText` is unavailable:
```js
// using `getBuiltinModule` rather than `import` makes this safe to run in non-Node-compatible environments
const styleText =
globalThis.process?.getBuiltinModule?.('node:util')?.styleText ??
((_format, text) => text);
```
In Node (engines require `>=22.17`, where `styleText` is present) behavior is unchanged; in non-Node runtimes module load no longer depends on a static `node:util` import, and `log_response` (if ever called) degrades to plain, uncolored output. Type check (`tsc --noEmit`) reports no errors for the file.
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: Rich-Harris <[email protected]>
dummdidumm
approved these changes
Aug 11, 2026
| let progress_line = noop; | ||
|
|
||
| if (is_tty) { | ||
| let current = false; |
Member
There was a problem hiding this comment.
Comment explaining what this is doing and why would be good
Co-authored-by: Simon H <[email protected]>
5 of 6 tasks
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.
small quality of life improvement — response logging is a bit quieter, especially when prerendering lots of stuff (as we do on svelte.dev for example)