-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Storybook loads stories from node_modules #19446
Comments
I tried the following pattern So I resorted to this to achieve compatibility with // ./.storybook/main.jsx
const path = require('path');
const findStories = (includePattern, excludePattern) => async () => {
const { globby } = await import('globby'); // globby is ESM only
const storybookFolderRelativePaths = await globby([includePattern, `!${excludePattern}`], {
cwd: path.join(process.cwd(), '.storybook'),
});
return storybookFolderRelativePaths;
};
module.exports = {
core: {
builder: 'webpack5',
},
stories: findStories('../packages/**/stories.{mdx,jsx}', '../packages/*/node_modules'),
// ...
}; I'm happy to make a contribution to the docs to add this as an example of how to achieve full compatibility with |
I'm experiencing this issue too. Any update on a fix for the root cause? |
Hey! I just wanted to say that this issue is still present with |
I solved this by only including my
|
Hey @V-iktor , So in this particular instance, it might not solve the issue, unless you're hoisting everything to the root node_modules (or if you have no dependencies between packages in the same monorepo). |
I´m using Yarn Workspaces (Monorepo) and it seems to have solved the problems on my Mac at least |
Ah I see, so the issue was never with yarn, as yarn hoists node_modules at the root. pnpm, on the contrary, uses a nested modules + symlinks approach, so this is why it wouldn't work... |
Closed by #22873 and available in both the latest prerelease & latest stable release |
Describe the bug
Storybook is loading stories from the
node_modules
folder.This happens especially in monorepos, where usually packages have co-located stories.
This is responsible at times for crashes of the dev server as well as memory leaks or generally bad user experience due to how slow storybook becomes compiling, even when the number of stories is not that high.
Can
node_modules
be always ignored by default please? I am expecting this, but perhaps I'm wrong.The issue definitely goes away listing the stories manually, even when the number of stories is above 100.
To Reproduce
After debugging storybook locally, I found out the issue here.
Essentially, the problem is linked to the fact that storybook is picking up stories from
node_modules
.I believe this can be seen in a pnpm monorepo, as pnpm creates a nested node_modules folder structure.
In my case it was like this:
So with a simple
./packages/**/stories.jsx
pattern in themain.js
file, all 3 stories files are loaded, rather than just 2.If you think about a monorepo, this can happen a lot if node_modules are not hoisted.
System
Additional context
This is mostly relevant to people using
pnpm
, but even when usingyarn
ornpm
,node_modules
are not necessarily always hoisted, as if there are conflicts in resolution, specific versions would be installed locally for a package rather than hoisted.I went further on investigating, and I can only see this behaviour in the
StoryIndexGenerator
usage ofglobby
, but that seems to be only used when thestoryStoreV7
feature is enabled. I think this is the same behaviour in the previous way to load stories (pre v7).The text was updated successfully, but these errors were encountered: