Skip to content

Conversation

@FrankFMY
Copy link
Contributor

@FrankFMY FrankFMY commented Feb 6, 2026

Summary

Fixes #13508

When a hooks.js or hooks.client.js file exists but doesn't export all possible hooks (e.g., only reroute without transport), Vite/Rollup emits MISSING_EXPORT warnings during build:

.svelte-kit/generated/client-optimized/app.js: "transport" is not exported by "src/hooks.ts"

Root cause

The generated app.js uses namespace imports (import * as universal_hooks from '...') and then accesses individual properties like universal_hooks.reroute or universal_hooks.transport. When a property isn't exported, Rollup detects this statically and warns.

A previous workaround (#13687) suppressed these warnings via onwarn, but the root cause remained.

Fix

Spread namespace imports into plain objects:

// Before
import * as universal_hooks from '...';
// universal_hooks.transport → MISSING_EXPORT warning

// After  
import * as _universal_hooks from '...';
const universal_hooks = { ..._universal_hooks };
// universal_hooks.transport → no warning (plain object, not namespace)

Rollup only checks property access on namespace imports (import * as ns). By spreading into a plain object, subsequent property access is no longer analyzed for missing exports.

This also removes the onwarn suppression workaround and the now-unused isRolldown variable.

Note: the server-side already handles this correctly via await import() destructuring (supported in the node18.13 target). The client-side targets chrome87/safari14 which don't support top-level await, making the spread approach the appropriate solution.

Test plan

  • Unit tests pass (pnpm -F @sveltejs/kit test:unit)
  • pnpm run lint — clean
  • pnpm run check — 0 errors
  • Integration tests with full hooks (basics — reroute + transport): 17 passed
  • Integration tests with partial hooks (hash-based-routing — reroute only, no transport): 10 passed
  • Integration tests with partial hooks (options-2 — transport only, no reroute): 1 passed
  • Verified generated code with dedent for all edge cases (no hooks, client-only, universal-only, both)

Spread namespace imports into plain objects so that Rollup/Rolldown
no longer warns about accessing potentially missing exports like
reroute, transport, handleError, or init from hooks files.

This removes the onwarn suppression workaround that was added in sveltejs#13687
and fixes the root cause of the issue.

Closes sveltejs#13508
@changeset-bot
Copy link

changeset-bot bot commented Feb 6, 2026

🦋 Changeset detected

Latest commit: c7a964d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transport & Reroute hooks are mandatory if hooks.(js|ts) exists

1 participant