Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: fails to import CSS files called "x.stories.css" or LESS files called "x.stories.less" #30687

Open
duncan-thacker opened this issue Feb 26, 2025 · 0 comments

Comments

@duncan-thacker
Copy link

Describe the bug

With Vite + React configured, importing a LESS file called "x.stories.less" causes story rendering to fail with the following error: "(intermediate value)(...) is not a function". The same problem affects CSS files called "x.stories.css".

Reproduction link

/~https://github.com/duncan-thacker/storybook-hmr-bug

Reproduction steps

  1. Clone the repo, do npm install, then npm run start. When visiting the only story, you will get an error saying "(intermediate value)(...) is not a function".
  2. In package.json, change the storybook package versions to 8.5.6, then npm install and npm run start. The error message is gone and the story works correctly.
  3. Revert back to 8.5.7, then rename sample.stories.less to sample.less, and change the corresponding import in sample.stories.js. This also fixes the problem (as HMR stripping is not applied)

System

System:
    OS: Windows 11 10.0.26100
    CPU: (32) x64 Intel(R) Core(TM) i9-14900KF
  Binaries:
    Node: 22.14.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD <----- active
  Browsers:
    Edge: Chromium (133.0.3065.59)
  npmPackages:
    @storybook/react: 8.5.7 => 8.5.7
    @storybook/react-vite: 8.5.7 => 8.5.7
    storybook: 8.5.7 => 8.5.7

Additional context

Likely cause

This occurs in 8.6.0 and 8.5.7, but not 8.5.6 so the culprit appears to be this PR: #30562, which adds HMR stripping to all files named x.stories.y. For this reason I suspect this bug affects many configurations - probably any where the builder supports HMR.

Workarounds

  • Renaming the LESS file so it doesn't match the "x.stories.less" pattern, or
  • Downgrading to Storybook 8.5.6

Potential fixes

Attempting to exclude stylesheet files (.css, .less, .scss) from HMR stripping would probably fix this issue (although as I'm not 100% sure what the benefit of HMR stripping is, it might be better to fix the HMR stripping to fix these special cases).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs Discussion
Development

No branches or pull requests

2 participants