Skip to content

Commit c7a964d

Browse files
committed
fix: resolve MISSING_EXPORT warnings for optional hooks exports
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 #13687 and fixes the root cause of the issue. Closes #13508
1 parent 3804428 commit c7a964d

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: avoid MISSING_EXPORT warnings for optional hooks by spreading namespace imports into plain objects

packages/kit/src/core/sync/write_client_manifest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ export function write_client_manifest(kit, manifest_data, output, metadata) {
142142
dedent`
143143
${
144144
client_hooks_file
145-
? `import * as client_hooks from '${relative_path(output, client_hooks_file)}';`
145+
? `import * as _client_hooks from '${relative_path(output, client_hooks_file)}';\nconst client_hooks = { ..._client_hooks };`
146146
: ''
147147
}
148148
${
149149
universal_hooks_file
150-
? `import * as universal_hooks from '${relative_path(output, universal_hooks_file)}';`
150+
? `import * as _universal_hooks from '${relative_path(output, universal_hooks_file)}';\nconst universal_hooks = { ..._universal_hooks };`
151151
: ''
152152
}
153153

packages/kit/src/exports/vite/index.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@ async function kit({ svelte_config }) {
190190
/** @type {import('vite')} */
191191
const vite = await import_peer('vite');
192192

193-
// @ts-ignore `vite.rolldownVersion` only exists in `rolldown-vite`
194-
const isRolldown = !!vite.rolldownVersion;
195-
196193
const { kit } = svelte_config;
197194
const out = `${kit.outDir}/output`;
198195

@@ -917,21 +914,7 @@ async function kit({ svelte_config }) {
917914
sourcemapIgnoreList,
918915
inlineDynamicImports: !split
919916
},
920-
preserveEntrySignatures: 'strict',
921-
onwarn(warning, handler) {
922-
if (
923-
(isRolldown
924-
? warning.code === 'IMPORT_IS_UNDEFINED'
925-
: warning.code === 'MISSING_EXPORT') &&
926-
warning.id === `${kit.outDir}/generated/client-optimized/app.js`
927-
) {
928-
// ignore e.g. undefined `handleError` hook when
929-
// referencing `client_hooks.handleError`
930-
return;
931-
}
932-
933-
handler(warning);
934-
}
917+
preserveEntrySignatures: 'strict'
935918
},
936919
ssrEmitAssets: true,
937920
target: ssr ? 'node18.13' : undefined

0 commit comments

Comments
 (0)