Storybook Build Failure: Sveltekit Remote Functions #32913
Replies: 1 comment
-
|
Hi @justindomingue! I'm Dosu and I’m helping the storybook team. To resolve build-time errors from The recommended approach is to create a mock file that exports the same named exports as
// .storybook/mocks/app-server.js
export function getRequestEvent() {
// no-op or return a dummy object
return {};
}
export function query(...args) {
// no-op or return a dummy function/promise
return () => {};
}
import path from 'path';
import type { StorybookConfig } from '@storybook/sveltekit';
const config: StorybookConfig = {
framework: '@storybook/sveltekit',
viteFinal: async (config) => {
config.resolve = config.resolve || {};
config.resolve.alias = {
...config.resolve.alias,
'$app/server': path.resolve(__dirname, './mocks/app-server.js'),
};
return config;
},
};
export default config;This ensures that during the build, any import from If you want to use automocking or file-based mocks, those are also supported and described in the Storybook docs. Make sure your mock exports match the real module's API to prevent further build errors. This approach is compatible with both build and dev modes in Storybook 1 2. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Issue Summary
pnpm build-storybookfails with module resolution error, whilepnpm storybook(dev mode) works fine.Error:
(3:11): "getPosts" is not exported by "src/posts.remote.ts"
Root Cause
The issue occurs because:
$app/serverfrom SvelteKit's runtime$app/serverdoesn't exist outside SvelteKit runtime contextMultiple files in the codebase import from
$app/server(specificallygetRequestEventandqueryfunctions).Example pattern:
Beta Was this translation helpful? Give feedback.
All reactions