storybookjs/storybook

[Bug]: Storybook 9 - Error messages are unclear when stories cannot be transformed

Open

#31128 opened on Apr 15, 2025

View on GitHub
 (1 comment) (2 reactions) (0 assignees)TypeScript (89,909 stars) (10,058 forks)batch import
addon: vitestbugdocumentationhelp wantedinternal-qa

Description

Describe the bug

Sometimes projects might have wrong setup (e.g. Svelte files are written incorrectly as can be seen in this repro)

And then Vitest is not able to produce test suites. The Storybook Vitest addon has a setup file that includes an afterEach call, which in such cases will fail as it cannot be attached to an actual test suite. However, from the error message it seems that it's a bug in Vitest, which is not necessarily the case:

The other side effect is that the source in the error message is not useful, as it relates to the internal setup file from the Storybook Vitest addon. If that code didn't execute, this is how things would look like, which is much better in context:

There are two things we can do:

  1. Add an FAQ entry to the docs, to make it clear to the user that it might not be a bug in Vitest, and that they need to investigate other logs that preceded that message
  2. Move the afterEach call into the transformed file. By moving it, we make it so that the afterEach is not executed when the file is not transformed, and therefore the stack trace will include a more accurate source where the code failed

Reproduction link

Reproduction steps

No response

System

-

Additional context

No response

Contributor guide