#SvelteKit Aliased imports with Storybook 7 Beta

5 messages · Page 1 of 1 (latest)

summer axle
#

Hello! I'm working with SvelteKit 1.0 and Storybook 7 Beta 25 and I'm trying to get aliased imports working.

In some of my components I include other components from, say, $lib/components where $lib = ./src/lib/. However while these imports work fine in my actual app, Storybook is not able to resolve them.

I tried adding the alias explicitly in my main.cjs file to no avail:

framework: {
  name: '@storybook/sveltekit',
  options: {}
},
async viteFinal(config, { configType }) {
  return mergeConfig(config, {
    resolve: {
      alias: {
        $lib: path.resolve('../src/lib')
      }
    }
  });
},

This does make it resolve the import but it doesn't actually work:
Failed to load url /abs-path-to-my-project/src/lib/components/MyComponent/MyComponent.svelte (resolved id: /abs-path-to-my-project/src/lib/components/MyComponent/MyComponent.svelte). Does the file exist?
This file does exist at that exact absolute path as well, so I'm not sure what's going wrong.

Is this just broken at the moment or is there anything to do to make it work?

versed shard
dire rain
#

And what Ian means by support is that you shouldn't have to specify that alias manually.

tulip obsidian
#

@versed shard does that also solve the unplugin imports issue with ~icons?