-
-
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
[Bug]: MDX breaks when importing a CSF from node_modules #27178
Comments
I've done some investigation but I don't yet know why this happens. The index looks fine: {
"v": 4,
"entries": {
"importedbutton--docs": {
"id": "importedbutton--docs",
"title": "ImportedButton",
"name": "Docs",
"importPath": "./stories/ImportedButton.mdx",
"storiesImports": [
"./node_modules/@monorepo/assets/src/ImportedButton.stories.js"
],
"type": "docs",
"tags": [
"dev",
"test",
"attached-mdx"
]
},
"importedbutton--imported-button": {
"type": "story",
"id": "importedbutton--imported-button",
"name": "Imported Button",
"title": "ImportedButton",
"importPath": "./node_modules/@monorepo/assets/src/ImportedButton.stories.js",
"tags": [
"dev",
"test"
]
}
}
} But storybook/code/lib/preview-api/src/modules/preview-web/docs-context/DocsContext.ts Line 148 in ba69532
undefined , even though the story is actually in this.exportsToCSFFile .
In the repro, using the debugger and doing the Seems like they are the same value but the references are different. I don't know if @tmeasday has insights into why this might happen. The fact that |
Thanks for the reproduction @stephiescastle. It looks like it is trying to do the right thing but the imported CSF file (from I think this is likely due to Vite's dependency prebundling leading to the file being imported twice. You can verify this by adding a I think @shilman's point remains that we don't officially support this and can't guarantee we won't break it in the future, but if you can figure out the workaround using something similar to this, please post here! (in viteFinal: (config) => ({
...config,
optimizeDeps: {
exclude: ['@monorepo/assets'],
},
}), |
Thanks @tmeasday. I tried working with However, I did try replacing pnpm's @monorepo/assets symlink with actual files. This fixed the issue without needing to customize the vite config, which helped me narrow down the problem to symlinks. Vite does have a preserveSymlinks option. However, setting
After both of those adjustments, things started working! Here's the commit that fixed the issue: stephiescastle/sb-repro-mdx-import-story@f6b0c89 |
Hey @stephiescastle - glad you figured it out. So I guess the TLDR is: You can import CSF from |
Describe the bug
When importing a CSF from a package in node_modules, the MDX documentation fails to render, with error:
The CSF file is captured by the
stories
glob in main.js, and if I remove the MDX file and set up autodocs, everything works fine.To Reproduce
I created a reproduction here: https://github.com/stephiescastle/sb-repro-mdx-import-story
Instructions are in the README and also below:
pnpm install
pnpm run --filter @monorepo/storybook storybook
System
Additional context
I am working in a monorepo via pnpm workspaces. The monorepo structure has been set up in the reproduction repository.
The text was updated successfully, but these errors were encountered: