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.

storybook-vite-source-loader-plugin + CSF3

See original GitHub issue

I found an issue that works fine in Storybook 6.4.0-rc.6 + Webpack but fails with storybook-builder-vite.

The underlying issue is at https://github.com/eirslett/storybook-builder-vite/blob/c2e9c3cc9c7879047e793a2c441a1cdd39f576e2/packages/storybook-builder-vite/source-loader-plugin.js#L10

The inject function from @storybook/source-loader does not export a sourceJson property. I don’t think it ever did. But regardless, things still generally works.

However, if I upgrade the storybook dependencies (see #161) and create a Storybook 6.4 Component Story Format 3.0 (CSF3) test, storybook-builder-vite does not properly transform the story file and ends up causing Storybook to crash with a defaultExport is undefined message.

The following is a valid CSF3 story:

export default {
  title: 'Gizmo',
  render: ({ label, ...props }) => <button {...props}>{label}</button>
};

export const Default = {
  args: {
    label: 'Hello, World'
  }
};

The key thing to note is that there is no function export (StoryFn), just a CSF3 StoryObj export. When transformed by storybook-vite-source-loader-plugin the resulting JS file is:

var __STORY__ = void 0;
var __LOCATIONS_MAP__ = {};
;
export const __namedExportsOrder = [];

I believe this has to do with the plugin bypassing the “standard” Storybook transformer and trying to do its own thing.

Oddly enough, if you add a standard function export (StoryFn), things actually work, including the CSF3 (StoryObj) export.

...
export const Weird = () => <div>Don't know why this "fixes" it.</div>;

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
scott-lccommented, Nov 24, 2021

@joshwooding - That is a much better solution and works perfectly for me.

I was under the impression that the transform could not be async, which was why that other solution existed in the first place.

0reactions
IanVScommented, Nov 24, 2021

Great teamwork! @joshwooding I’ll review a PR if you would like to submit it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

storybook-vite-source-loader-plugin + CSF3 #164 - GitHub
I found an issue that works fine in Storybook 6.4.0-rc.6 + Webpack but fails with storybook-builder-vite. The underlying issue is at ...
Read more >
Vite - Storybook
Storybook Vite builder bundles your components and stories with Vite, a fast ESM bundler. For applications built with Vite: it allows reusing the...
Read more >
@storybook/source-loader | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
@storybook/router: Versions | Openbase
Full version history for @storybook/router including change logs.
Read more >
@storybook/csf-tools - NPM Package Versions - Socket - Socket.dev
An experimental library to read, analyze, transform, and write CSF programmatically. Version: 6.5.0-beta.0 was published by shilman.
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