Unable to display stories for custom components #33382
-
SummaryFor the past 2 days, I have been unable to render my stories, I just have many components and none of them work because of one error: I have scoured all parts of the internet, but I cannot find a fix to the error. It's very frustrating. Steps to reproduce, you can clone the repository, then simply run Find my main.ts, package.json, preview.ts files attached below: main.ts Package.json preview.ts Looking forward to a response Additional informationI'm using Storybook 10, I also have better-auth setup, I suspect that it will need module mocking Create a reproductionNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
|
Hi @SanguineTitan57! I'm Dosu and I’m helping the storybook team. This error is likely caused by a module resolution issue in Storybook 10 with Next.js and Vite, especially on Windows. Here’s what you can do:
You can find more details and troubleshooting steps in the Next.js Vite framework docs. Try these steps and let me know if the error persists or if you see a different message. If possible, share the full error stack trace from chunk-E42WOUFD.js for more targeted help. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
You're running into two separate issues: the Node.js API error and the loss of Tailwind styling. Here’s how to address both:
1. Fixing the "createRequire is not a function" error:
This error means server-only code (like better-auth) is leaking into your browser bundle. To prevent this, you need to alias all server-only modules to pure ESM mock files that export stubs or empty objects—no Node.js APIs or side effects.
Place mocks for external packages (like better-auth) in a root
__mocks__directory (at your project root, next to.storybook). For example, create__mocks__/better-auth.js(must be.jsand ESM, not TypeScript or CJS):