Shim SvelteKit runtime import aliases / Importing `$app/*` fails
See original GitHub issueDescribe the bug
As far as I can tell there’s no way to use sveltekit runtime imports (eg: $app/navigation
) outside of sveltekit dev/build. Which makes testing virtually impossible. If there is a way to shim these imports outside of the main sveltekit context I haven’t found it, so perhaps documentation is needed.
My particular use-case is with Storybook, where UI components that rely on any sveltekit modules break the whole setup. I tried aliasing them with webpack (pointing to .svelte-kit/dev/...
) but that didn’t work either.
Another use-case is publishing components for sveltekit that would need to rely on those imports.
To Reproduce
- Setup storybook with Sveltekit
- Create a component that imports a runtime module (eg:
$app/env
) - Run storybook and see if fail (
cannot resolve module $app/env
)
Severity Not blocking, but makes building a component library with Storybook or other development/testing frameworks impossible. So, severe annoyance?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:11
- Comments:30 (16 by maintainers)
Top GitHub Comments
Here’s the test mock we’ve been using to handle
$app/stores
. It doesn’t handle things likeimport.meta.env
.So you just pass it the actual component to be tested and (optionally) the stores you want to use for
$app/stores
.EDIT: Added spreading of other props onto the component to be tested.
https://github.com/michaelwooley/storybook-experimental-vite demonstrates setting up Storybook with the new
vite.config.js
. We still need to figure out how to handle$navigation
and$stores