Svelte

fix: don't bundle @sveltejs/kit

#13971

Closing issues

Pull request

Merged
R
Rich-Harris
Jul 9, 2025, 12:26 AM

closes

We've had a long-running battle with instanceof checks inside the codebase: when you call error(...) or redirect(...) in your code, SvelteKit needs to check that the thrown object is an instance of HttpError or Redirect.

Recently we tried , which attempts to ensure that any of your dependencies that depend on @sveltejs/kit are bundled, since @sveltejs/kit is also bundled, and that means that your app will only have a single copy of SvelteKit (and classes like HttpError) in memory. But that has problems of its own.

This PR goes in the opposite direction, by making it possible to not bundle @sveltejs/kit in the first place. Aside from being a lot simpler, this feels more correct. The one compromise is that we need to expose a @sveltejs/kit/internal package so that classes can be shared between code in @sveltejs/kit and code in $app/... (which is bundled, necessarily, as it relies on virtual modules etc). But because we're controlling how types/index.d.ts is generated, this module is invisible to TypeScript (and therefore won't show up in import autocomplete suggestions etc).


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • 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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • 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

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Info

Merged at Jul 9, 2025, 12:26 PM
Merged by Rich-Harris
Assignees None
Reviewers None
Labels None
Milestone None

Pro tip: You can prefix GitHub URLs of issues, PRs or discussions with svcl.dev/ to view them on this page! Also try it on a GitHub release ;)