Comments (8)
Certainly! Here's a suggested best reply/solution for the reported issue on GitHub:
Bug Description
When attempting to use MUI's Drawer
component in a Storybook story, an error occurs. This issue was observed after upgrading from Storybook 7 to Storybook 8.
To Reproduce
Repository: Drawer App
The project includes two components and their respective stories. The stories in the MyBox
component, using Box
, are displayed correctly. However, the stories in the MyDrawer
component, using Drawer
, generate the following error:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
System Information
System:
- OS: macOS 14.2.1
- CPU: (8) arm64 Apple M1
- Shell: 5.9 - /bin/zsh
Binaries:
- Node: 18.18.2 - ~/.nvm/versions/node/v18.18.2/bin/node
- npm: 9.8.1 - ~/.nvm/versions/node/v18.18.2/bin/npm <----- active
Browsers:
- Chrome: 123.0.6312.59
- Edge: 123.0.2420.53
npmPackages:
- @storybook/addon-essentials: ^8.0.4
- @storybook/addon-interactions: ^8.0.4
- @storybook/addon-links: ^8.0.4
- @storybook/addon-onboarding: ^8.0.4
- @storybook/blocks: ^8.0.4
- @storybook/nextjs: ^8.0.4
- @storybook/react: ^8.0.4
- @storybook/test: ^8.0.4
- eslint-plugin-storybook: ^0.8.0
- storybook: ^8.0.4
Solution
The issue likely arises from the way the Drawer
component is imported and used. To resolve this issue, ensure the correct import statement for Drawer
from @mui/material
:
import React from "react";
import Drawer from "@mui/material/Drawer";
export default function MyDrawer() {
return <Drawer open>My Drawer</Drawer>;
}
Additional Notes
- This solution assumes that
Drawer
is a default export from@mui/material/Drawer
. - Verify that the import path is correct and that
Drawer
is correctly exported from the@mui/material
library. - If the issue persists, double-check the Storybook configuration and ensure compatibility with the version of MUI being used.
Feel free to customize this response as needed for your GitHub issue. It includes the bug description, steps to reproduce, system information, suggested solution, and additional notes to assist with resolving the issue.
from storybook.
Thanks for the workarounds! I'm still hoping this gets fixed at some point - I don't really see myself rewriting/bloating our rather huge project just to make Storybook happy. :/
from storybook.
I'm having the same issue after updating to version 8.
from storybook.
I think not only drawer had the issue, InputBase
also facing same issue in storybook 8.0.5
I had to manually change to default import to solve:
From:
import {
Drawer,
InputBase
} from '@mui/material'
To:
import Drawer from '@mui/material/Drawer'
import InputBase from '@mui/material/InputBase'
from storybook.
Hi @sunvisor
Thank you for sharing your issue!
I have a guess what the root cause might be, and I would like to ask you to try something out:
Could you please opt-out for react-docgen-typescript
?
In Storybook 8, we changed the default component analysis tool from react-docgen-typescript
to react-docgen
. We got a lot of reports that, in some edge cases, the analysis tool doesn't extract component information properly and even leads to breaking stories.
You can read about this in the migration guide: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#react-docgen-component-analysis-by-default
I want to try out, whether the error disappears if you use the former default react-docgen-typescript
. For that, go to your .storybook/main.js|ts
file and configure the following:
export default {
+ typescript: {
+ reactDocgen: "react-docgen-typescript",
+ },
};
from storybook.
@valentinpalkovic
Thank you for the response! Speaking for me, switching back to react-docgen-typecript
didn't fix the behavior. But maybe somebody else test it, too ... just in case there's something else in my config which screws up.
from storybook.
Hi @sunvisor
Thank you for sharing your issue!
I have a guess what the root cause might be, and I would like to ask you to try something out:
Could you please opt-out for
react-docgen-typescript
? In Storybook 8, we changed the default component analysis tool fromreact-docgen-typescript
toreact-docgen
. We got a lot of reports that, in some edge cases, the analysis tool doesn't extract component information properly and even leads to breaking stories.You can read about this in the migration guide: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#react-docgen-component-analysis-by-default
I want to try out, whether the error disappears if you use the former default
react-docgen-typescript
. For that, go to your.storybook/main.js|ts
file and configure the following:export default { + typescript: { + reactDocgen: "react-docgen-typescript", + }, };
Thank you.
I have tried your suggestion.
But the result is not good.
I get exactly the same error.
from storybook.
Thanks.
Indeed, I changed the import statement as you suggested and the error no longer occurs.
Now I am wondering if I should modify my code to accommodate or wait for storybook to improve and upgrade to version 8.
Anyway, thanks for sharing your solution.
from storybook.
Related Issues (20)
- [Bug]: Uncaught TypeError: Refresh.isLikelyComponentType is not a function HOT 3
- In @storybook/addon-docs react has been moved from peerDependencies to dependencies HOT 1
- [Bug]: Angular - Wrong detection of standalone components when inheriting HOT 1
- RollupError: "X" is not exported by "../constants/dist/index.js", imported by "path/file.tsx".
- [Bug]: find-implicit-spies codemod doesn't exist HOT 2
- [Project SfC]: Preview - Error screen adjustments HOT 1
- Could not resolve "./sb-preview/runtime.js" from "iframe.html"
- [Bug]: Cannot find module 'react-dom/client' with portable stories in React 17 projects. HOT 2
- [Bug]: next/font/local is not worked in storybook with vanilla Extract HOT 2
- [Project SfC]: Create the frontend to create a new story file from scratch
- [Bug]: The error message is that there is no default export. HOT 1
- [Bug]: Storybook Server 8.0.8 autodoc error - Element type is invalid
- [Bug]: `useParams` returns null in NextJS 14.2. Storybook 7 & 8 HOT 2
- [Bug]: Deploying to Github Pages is creating `assets/assets` path
- [Bug]: The accessibility scan encountered an error. {"name":"TypeError"} HOT 2
- [Bug]: Module parse failed: Unexpected token HOT 3
- [Bug]: Missing "./dist/react-18" after upgrading storybook to v8 with vitejs v5 HOT 2
- [Project SfC]: Testing
- [Bug]: Storybook doesn't run with tailwindcss in next.js HOT 2
- [Bug]: Vue3 After upgrading to V7 (and v8) controls are not reactive
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from storybook.