-
Notifications
You must be signed in to change notification settings - Fork 106
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] - Vite transforming of stories is slow or hangs #577
Comments
Can you check what version of Aside from that, Vite is known to run out of memory when building, so I'd suggest increasing the memory available to node using something like |
Here is the version info:
|
There is a 0.2.3 version of @joshwooding/vite-plugin-react-docgen-typescript. I could force the use of a newer version? |
Version 0.2.2 had a perf regression, but 0.2.1 should be fine. Did you try increasing the available memory to node? |
The other thing you can do is take a look at the network tab when loading a story in dev mode, and see if unexpected packages are being loaded, for example through |
I did bump the memory for node. After about 28 minutes the transforming blew chunks and did point out an error with an icon we were trying to import. The developer was trying to import it using the wrong name. I corrected this and kicked off another build-storybook. Right now its hanging on transforming (72) ../../node_modules/date-fns/esm/locale/index.js. But I'll give it time. I'm running this on a M1-Max with 64 gigs of memory. |
Ok. It finished. Took about 15 minutes. |
How many stories do you have, and do you use barrel imports (index files)? |
10 stories total and yes we do use barrel imports. The transforming process takes a long time with the following dependencies:
|
I also use a few functions from Maybe you can create a minimal reproduction that I can look into? |
We'll I must doing something wrong. Lol. I'll see what I can do to create a repo you can examine. When it does complete it provides these suggestions:
|
I'm testing with no stories. Hangs on transforming @storybook/addon-outline/dist/chunk-2DMOCDBJ.mjs |
I don't know if I mentioned it but we're using an NPM monorepo. So our node_modules is located outside of the project. |
Does it speed up if you disable docgen? That will help narrow down where the problem is happening. Put this in your storybook config: typescript: {
reactDocgen: false,
} |
It speeds up but still hangs for a long time on: Is the issue the monorepo structure? |
I'm not sure. You could try moving storybook to one of the packages in the monorepo and see if that makes a big difference. Coming up with documentation for best practices for monorepos is on the team's radar, you can give an upvote to storybookjs/storybook#22271 if you think that'd be useful. |
Moving the code out of the monorepo did make a difference. Build completed in 9 seconds. I wonder if its the linked dependencies that might be the issue? |
After setting a sampleStorybook within our monorepo project it looks like its our linked dependencies from our other packages within the monorepo that are slowing thing things down. |
@visualjeff one thing I forgot to mention that you could try, is using vite's |
I want to share a workaround to improve build performance which I'm doing in my project. Project structureMy project has this structure:
Project conventionsMy team only wants to create story files for reusuable UI components, which means the components that reflect design system only and these components have no dependencies on things like APIs or translation. Introducing workaroundIn
Investigation and findingsWhat I've discovered was: when serving or building Storybook, Vite will try to:
Benefits of the workaround
I hope this helps! |
Any traction on this one? I'm experiencing what sounds like the same issue, also in a monorepo. Storybook build takes about 12mins for me. |
Could you elaborate on this one? Are barrel files not recommended or supported? We use them quite extensively. |
Barrel files are generally not recommended, due to the potential for increasing your bundle size if tree-shaking is not working perfectly. And they can also cause problems with vite's HMR, see vitejs/vite-plugin-react-swc#41 (comment). There's a plugin that you can try out, which may help: vitejs/vite#8237 (comment) |
I am experiencing the same problem I tried the above solution but does not work started happening in an nx monorepo, typescript with vite storybook build just hangs. node version 20.11.0 |
I tried a lot of different things also reverting vite with no success, if i run verbose i see the command hangs on |
@satanshiro I had the same issue in an Nx monorepo in the last few days. The Storybook build task with [Nx Vite TsPaths] Resolved vite/preload-helper.js to undefined
transforming (554) ../../node_modules/@storybook/addon-docs/node_modules/@storybook/components/dist/WithTooltip-V3YHNWJZ.mjs I tried several fixes mentioned above, but saw no improvement or error reported. Eventually I upgraded my Storybook config to use the [Nx Vite TsPaths] Resolved vite/preload-helper.js to undefined
x Build failed in 1.08s
=> Failed to build the preview
Error: Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:
(vite:esbuild) transform "./.storybook/preview.ts"
(vite:esbuild) transform "./src/lib/vitelib.stories.tsx" So I tried removing Vite plugins and found that viteFinal: (config) => {
const filteredPlugins = config.plugins?.filter(plugin => plugin?.name !== "vite:dts") ?? [];
return { ...config, plugins: filteredPlugins };
}, This worked for my Nx 18 library with Storybook. Hope it's helpful for you. |
Upgrading to vite |
I'm on storybook 8.2.9 and vite 5.4.2. The latest storybook version builds much slower than storybook 7.6.16, and it runs out of memory even with Please feel free to let me know if there is any detailed logs that I can provide to help with debugging. Thanks! |
What version of
vite
are you using?4.3.8
System info and storybook versions
System:
OS: macOS 13.3.1
CPU: (10) arm64 Apple M1 Max
Binaries:
Node: 18.4.0 - ~/.nvm/versions/node/v18.4.0/bin/node
npm: 8.12.1 - ~/.nvm/versions/node/v18.4.0/bin/npm
Browsers:
Chrome: 113.0.5672.126
Edge: 111.0.1661.62
Safari: 16.4
npmPackages:
@storybook/addon-a11y: ^7.0.12 => 7.0.12
@storybook/addon-actions: ^7.0.12 => 7.0.12
@storybook/addon-essentials: ^7.0.12 => 7.0.12
@storybook/addon-interactions: ^7.0.12 => 7.0.12
@storybook/addon-jest: ^7.0.12 => 7.0.12
@storybook/addon-links: ^7.0.12 => 7.0.12
@storybook/addon-styling: ^1.0.8 => 1.0.8
@storybook/blocks: ^7.0.12 => 7.0.12
@storybook/react: ^7.0.12 => 7.0.12
@storybook/react-vite: ^7.0.12 => 7.0.12
@storybook/testing-library: ^0.0.14-next.2 => 0.0.14-next.2
Describe the Bug
We have two Storybook 7 / Vite projects. One builds and renders but it takes some time. The other one just hangs and never recovers. The only difference between the two is the complexity of the stories. The project with the more complex stories just hangs. When running storybook build the project gets stuck with transforming and just hangs.
Here is our main.js
Our preview.jsx
Thank you.
Link to Minimal Reproducible Example
No response
Participation
The text was updated successfully, but these errors were encountered: