question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[7.0] Incompatible with sveltekit

See original GitHub issue

Describe the bug A standard bootstrap of a sveltekit + storybook project fails to start.

To Reproduce

  • yarn create svelte
  • follow the prompts, choose skeleton for the template and no for everything else
  • yarn
  • npx sb@future init
  • yarn storybook
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/ianvs/code/experiments/sveltekit-generator/node_modules/@sveltejs/adapter-auto/package.json

It seems like this happens because of a require call here: https://github.com/storybookjs/storybook/blob/b42f0edea70f4f97d1d64aa86945f3beeff2a7b7/code/lib/core-common/src/utils/interpret-require.ts#L24

But sveltekit is ESM-only. I tried changing the generated .storybook/main.cjs file into esm, but that still didn’t help.

System N/A

Additional context I’ve requested a way to specify all sveltekit options via command line flags, so that we can create a repro template for sveltekit and add it to our test suite: https://github.com/sveltejs/kit/issues/7064

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:40 (34 by maintainers)

github_iconTop GitHub Comments

3reactions
JReinholdcommented, Oct 17, 2022

I’ll do a follow up PR that removes the SvelteKit Vite plugin.

Are there particular features you’re thinking of? If you don’t build the SvelteKit generated code such as the route handlers, I’m not sure you’re left with much…

I think it’s mainly importing the SvelteKit specific modules. I agree most of them don’t make sense in a deep component that you’d have in a Storybook story, eg. @sveltejs/kit/hooks doesn’t make sense in a Storybook context. But I can see some of them make sense, eg.:

  • $app/environment - As @Amerlander mentions should probably always be browser in SB
  • Supporting any $lib/ imports - I’d guess is just a simple Vite alias.
  • $app/paths - components showing the current URL or a path to an asset or whatever
  • $app/stores - the page and the navigation stores could be useful for components that navigates.

But I think all of these should ideally be treated similar to props (or “args”), so users could “mock” them or define them as needed per story. Setting the current page for a given story, or making $app/navigation/goto call a Storybook action when called. I think all of this is out of scope for our SvelteKit support for now, but I think it would be the ideal DX for anyone or the community to build.

My hunch is that the biggest annoyance would be that we don’t support $lib/ imports, I can see that being used quite often in any component.

1reaction
Amerlandercommented, Oct 18, 2022

I agree with benmccann. But I can give some examples for SvelteKit-specific code I used in my components and had to change to use with Storybook. It were only about the SvelteKit specific $app/environment browser variable and $app/stores page store:

I have a menu component which uses the page store:

import { page } from '$app/stores'
$: active = $page.url.pathname;

I haven’t thought about a workaround yet, I just decided to not add this component to storybook for now.

And I had components which used the browser variable to prevent code from being ssr. Those components are already changed to not use browser anymore and I think that also improved the components. Also, I think the browser variable for example could be hard coded to be always true in storybook and then easily be used.

I would rather prefer to be able to build storybook than to have these sveltekit specific things available.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[7.0] Incompatible with sveltekit #19280 - Issuehunt
Describe the bug A standard bootstrap of a sveltekit + storybook project fails to start. To Reproduce. yarn create svelte; follow the prompts, ......
Read more >
run command failing on newest version of sveltekit : r/sveltejs
Hi guys I have a digital ocean node setup with sveltekit, until now I ran the app like this node build/index.js but now...
Read more >
Error installing sveltekit app after upgrading Node to latest ...
The version you've got cached locally could be incompatible with the current version of SvelteKit. Alternative things to try:.
Read more >
Major Svelte Kit API Change - Fixing `load`, and tightening up ...
https://github.com/sveltejs/kit/discussions/5748Simple Made Easy: https://www.youtube.com/watch?v=SxdOUGdseq4Become a Level Up Pro and take ...
Read more >
SvelteKit Crash Course Tutorial #7 - Reset Layouts - YouTube
Get access to this course on Net Ninja Pro:https://netninja.dev/p/ sveltekit -tutorial Get access to more premium courses on Net Ninja ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found