fix: bundle entrypoints alongside app code#16069
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 071726d 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 |
elliott-with-the-longest-name-on-github
approved these changes
Jun 17, 2026
elliott-with-the-longest-name-on-github
left a comment
Contributor
There was a problem hiding this comment.
lgtm
…nd `PRERENDERED`, and its `declare global { } export {}` form turns the file into a module which additionally breaks the ambient `MANIFEST`/`SERVER` module declarations — all causing `pnpm check` (tsc with checkJs) to fail.
This commit fixes the issue reported at packages/adapter-node/internal.d.ts:11
## Bug
The PR moves `base`/`prerendered` from imported `MANIFEST` values to injected global constants `BASE`/`PRERENDERED` (via `@rollup/plugin-replace`). `src/handler.js` now references them:
```js
const prerendered = PRERENDERED; // line 19
const asset_dir = `
```
But `internal.d.ts` only declared `ENV_PREFIX` and `PRECOMPRESS`. Since `tsconfig.json` has `checkJs: true` and includes `src/**/*.js`, `pnpm check` (`tsc`) fails.
Running `pnpm check` on the PR state produced:
```
src/handler.js(9,24): error TS2307: Cannot find module 'SERVER' ...
src/handler.js(10,26): error TS2307: Cannot find module 'MANIFEST' ...
src/handler.js(19,21): error TS2552: Cannot find name 'PRERENDERED'.
src/handler.js(42,35): error TS2304: Cannot find name 'BASE'.
src/handler.js(46,9): error TS7006: Parameter 'file' implicitly has an 'any' type.
```
So there were actually **two** problems, both introduced by the `internal.d.ts` refactor:
1. **Missing globals** — `BASE` and `PRERENDERED` were never declared (the reported issue).
2. **Broken ambient module declarations** — the new `declare global { ... }` block requires the file to be a module, which the PR achieved by adding `export {};`. Converting `internal.d.ts` into a module caused the ambient `declare module 'MANIFEST'` and `declare module 'SERVER'` declarations to stop resolving for `handler.js` (`TS2307`). That in turn made `manifest` typed as `any`, which cascaded into the `TS7006` implicit-`any` on the `read: (file) => ...` callback.
The baseline (pre-PR) `internal.d.ts` was a *script* (no top-level `import`/`export`), so its `declare module` declarations were ambient and globally visible — and `pnpm check` passed cleanly there.
## Fix
Keep `internal.d.ts` as a script file and declare the four globals at top level with `declare const`, instead of using `declare global { } export {}`:
```ts
declare const BASE: string;
declare const ENV_PREFIX: string;
declare const PRECOMPRESS: boolean;
declare const PRERENDERED: Set<string>;
```
`PRERENDERED` is typed as `Set<string>` because `handler.js` uses `prerendered.has(...)`, and `BASE` as `string` (used in a template literal). Because the file is no longer a module, the ambient `MANIFEST`/`SERVER` declarations resolve again, which also removes the cascading implicit-`any` error.
After the fix, `pnpm check` passes with no errors and `prettier --check` is clean.
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: Rich-Harris <hello@rich-harris.dev>
…whole-word `BASE` identifier in user/3rd-party server code gets silently replaced with the base-path string, corrupting code or breaking the build.
This commit fixes the issue reported at packages/adapter-node/index.js:86
## Bug
In `packages/adapter-node/index.js`, `adapt()` runs a Rollup build that bundles the adapter's `entries/*` files **together with** the user's Vite server output (resolved via the `SERVER`/`MANIFEST` aliases → `builder.getServerDirectory()`), which includes the user's server code and any bundled `devDependencies`.
The newly added `replace()` plugin had no `include`/`exclude`:
```js
replace({
values: {
BASE: JSON.stringify(builder.config.kit.paths.base),
ENV_PREFIX: JSON.stringify(envPrefix),
PRECOMPRESS: JSON.stringify(precompress),
PRERENDERED: `new Set(
```
`@rollup/plugin-replace` transforms **every** module in the bundle and matches whole-word tokens (default delimiters `['\b','\b']`). So app or dependency code such as:
```js
const BASE = process.env.API_BASE; // -> const "" = process.env.API_BASE; (syntax error)
import { BASE } from './config.js';
```
would have the bare `BASE` identifier replaced with the configured base path (e.g. `""`), producing broken code or silently wrong behavior. `ENV_PREFIX`/`PRECOMPRESS`/`PRERENDERED` are unlikely to collide, but `BASE` is a very plausible real-world identifier.
This is a regression from the previous approach, where replacement was scoped to the adapter's own copied files via `builder.copy(files, out, { replace: {...} })` (see commit `ab3f210`).
### Concrete trigger
A SvelteKit project built with `adapter-node` whose server code (or a bundled devDependency) declares/imports an identifier named `BASE` — the build either fails with a syntax error or emits corrupted server code.
## Fix
Scope the plugin to only the adapter's entrypoints by adding an `include`:
```js
include: [`
```
`tmp` is an absolute path (`config.kit.outDir` is `path.resolve`d, then `/adapter-node`), and all four tokens are used only in `src/env.js`/`src/handler.js`, which are copied into . `@rollup/pluginutils`' `createFilter` normalizes paths, so the glob matches the entry module IDs while excluding the bundled app/dependency modules.
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: Rich-Harris <hello@rich-harris.dev>
Merged
Rich-Harris
pushed a commit
that referenced
this pull request
Jun 18, 2026
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @sveltejs/enhanced-img@0.11.0 ### Minor Changes - feat: export `EnhancedImgAttributes` type ([#15649](#15649)) ### Patch Changes - fix: exclude imports with `?` character from transformation ([#15617](#15617)) ## @sveltejs/kit@2.66.0 ### Minor Changes - feat: precompress prerendered `.md` and `.mdx` files ([#15893](#15893)) - feat: warn the user when they forget to make boolean inputs optional in their form schemas ([#15804](#15804)) ### Patch Changes - fix: blur active element before component update during navigation so that blur/focusout handlers fire while old component data is still valid ([#15452](#15452)) - fix: ensure `base` is available from `$service-worker` during development ([#15882](#15882)) - fix: use correct relative asset paths when rendering an error page for a missing `__data.json` request ([#15884](#15884)) - fix: preserve active `for await` consumers across `query.live` reconnects ([#16022](#16022)) - fix: settle `query.live` reconnect promise on all exit paths, preventing `invalidateAll()` from deadlocking when a live query is offline or interrupted ([#16022](#16022)) - fix: preserve last value when a `query.live` stream completes without yielding on reconnect ([#16022](#16022)) - fix: remove `types: ['node']` from generated tsconfig to avoid errors when `@types/node` is not installed ([#15709](#15709)) - fix: prefer pages over endpoints when prerendering ([#16076](#16076)) - fix: restore snapshots after afterNavigate callbacks ([#16066](#16066)) - fix: support `ws:`/`wss:` and `trusted-types-eval` for CSP sources ([#15938](#15938)) - fix: omit empty `file` inputs from remote form data ([#15898](#15898)) - fix: fail early if a route with `+page` and `+server` is marked as prerenderable ([#16075](#16075)) - fix: wait a tick before resetting forms ([#15805](#15805)) - fix: `preflight` schemas apply correctly when chained before `for` ([#15863](#15863)) - fix: blank page in SPA mode when root layout `load()` throws ([#15798](#15798)) - fix: pass all unknown options from the `sveltekit` Vite plugin through to `vite-plugin-svelte` ([#16010](#16010)) ## @sveltejs/adapter-node@5.5.5 ### Patch Changes - fix: bundle entrypoints alongside app code ([#16069](#16069)) - fix: log the actual adapter-node listening address ([#15899](#15899)) - Updated dependencies [[`63f1b0b`](63f1b0b), [`1dbff3f`](1dbff3f), [`961ba01`](961ba01), [`d2e108c`](d2e108c), [`d2e108c`](d2e108c), [`d2e108c`](d2e108c), [`860b3c7`](860b3c7), [`f8c842c`](f8c842c), [`d3aa5fe`](d3aa5fe), [`0dd7659`](0dd7659), [`03e9f66`](03e9f66), [`57b7b7b`](57b7b7b), [`4eabadc`](4eabadc), [`6fbf2b6`](6fbf2b6), [`276744d`](276744d), [`8740132`](8740132), [`f430a68`](f430a68), [`1c7a8dc`](1c7a8dc)]: - @sveltejs/kit@2.66.0 ## @sveltejs/adapter-vercel@6.3.4 ### Patch Changes - fix: prevent missing immutable assets from being cached as 404s for a year ([#16077](#16077)) - Updated dependencies [[`63f1b0b`](63f1b0b), [`1dbff3f`](1dbff3f), [`961ba01`](961ba01), [`d2e108c`](d2e108c), [`d2e108c`](d2e108c), [`d2e108c`](d2e108c), [`860b3c7`](860b3c7), [`f8c842c`](f8c842c), [`d3aa5fe`](d3aa5fe), [`0dd7659`](0dd7659), [`03e9f66`](03e9f66), [`57b7b7b`](57b7b7b), [`4eabadc`](4eabadc), [`6fbf2b6`](6fbf2b6), [`276744d`](276744d), [`8740132`](8740132), [`f430a68`](f430a68), [`1c7a8dc`](1c7a8dc)]: - @sveltejs/kit@2.66.0 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
huskas-2189
pushed a commit
to huskas-2189/Bookmark
that referenced
this pull request
Jun 20, 2026
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [@sveltejs/adapter-node](https://svelte.dev/docs/kit/adapter-node) ([source](https://github.com/sveltejs/kit/tree/HEAD/packages/adapter-node)) | [`5.5.4` → `5.5.5`](https://renovatebot.com/diffs/npm/@sveltejs%2fadapter-node/5.5.4/5.5.5) |  |  | --- ### Release Notes <details> <summary>sveltejs/kit (@​sveltejs/adapter-node)</summary> ### [`v5.5.5`](https://github.com/sveltejs/kit/blob/HEAD/packages/adapter-node/CHANGELOG.md#555) [Compare Source](https://github.com/sveltejs/kit/compare/@sveltejs/adapter-node@5.5.4...@sveltejs/adapter-node@5.5.5) ##### Patch Changes - fix: bundle entrypoints alongside app code ([#​16069](sveltejs/kit#16069)) - fix: log the actual adapter-node listening address ([#​15899](sveltejs/kit#15899)) - Updated dependencies \[[`63f1b0b`](sveltejs/kit@63f1b0b), [`1dbff3f`](sveltejs/kit@1dbff3f), [`961ba01`](sveltejs/kit@961ba01), [`d2e108c`](sveltejs/kit@d2e108c), [`d2e108c`](sveltejs/kit@d2e108c), [`d2e108c`](sveltejs/kit@d2e108c), [`860b3c7`](sveltejs/kit@860b3c7), [`f8c842c`](sveltejs/kit@f8c842c), [`d3aa5fe`](sveltejs/kit@d3aa5fe), [`0dd7659`](sveltejs/kit@0dd7659), [`03e9f66`](sveltejs/kit@03e9f66), [`57b7b7b`](sveltejs/kit@57b7b7b), [`4eabadc`](sveltejs/kit@4eabadc), [`6fbf2b6`](sveltejs/kit@6fbf2b6), [`276744d`](sveltejs/kit@276744d), [`8740132`](sveltejs/kit@8740132), [`f430a68`](sveltejs/kit@f430a68), [`1c7a8dc`](sveltejs/kit@1c7a8dc)]: - [@​sveltejs/kit](https://github.com/sveltejs/kit)@​2.66.0 </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled because a matching PR was automerged previously. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yMjAuMCIsInVwZGF0ZWRJblZlciI6IjQzLjIyMC4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6W119--> Reviewed-on: https://codeberg.org/huskas-2189/Bookmark/pulls/123
6 tasks
Rich-Harris
added a commit
that referenced
this pull request
Jun 22, 2026
closes #16092 This PR tries to keep the benefits of #16069 while ensuring the Node adapter handler code and the user's server build output are in separate chunks. Doing so avoids the circular dependency that causes the app to crash on startup. --- ### Please don't delete this checklist! Before submitting the PR, please make sure you do the following: - [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs - [x] This message body should clearly illustrate what problems it solves. - [x] Ideally, include a test that fails without this PR but passes with it. - see #16104 ### Tests - [x] Run the tests with `pnpm test` and lint the project with `pnpm lint` and `pnpm check` ### Changesets - [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running `pnpm changeset` and following the prompts. Changesets that add features should be `minor` and those that fix bugs should be `patch`. Please prefix changeset messages with `feat:`, `fix:`, or `chore:`. ### Edits - [x] Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed. --------- Co-authored-by: Rich Harris <richard.a.harris@gmail.com> Co-authored-by: Rich Harris <rich.harris@vercel.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.
closes #15755. By bundling the adapter entry points and the already-Vite-bundled app code together, we prevent multiple copies of things like
SvelteKitErrorPlease don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits