storybook: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
E

E

l

e

ment 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. Check the render method of Strategy.
Invariant Violation: 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.
Check the render method of Strategy.
at invariant (http://localhost:6006/static/iframe.bundle.js:24211:15)
at createFiberFromTypeAndProps (http://localhost:6006/static/iframe.bundle.js:34114:11)
at createFiberFromElement (http://localhost:6006/static/iframe.bundle.js:34135:15)
at createChild (http://localhost:6006/static/iframe.bundle.js:37304:28)
at reconcileChildrenArray (http://localhost:6006/static/iframe.bundle.js:37555:25)
at reconcileChildFibers (http://localhost:6006/static/iframe.bundle.js:37878:14)
at reconcileChildren (http://localhost:6006/static/iframe.bundle.js:38234:28)
at updateHostComponent (http://localhost:6006/static/iframe.bundle.js:38579:3)
at beginWork (http://localhost:6006/static/iframe.bundle.js:39243:14)
at performUnitOfWork (http://localhost:6006/static/iframe.bundle.js:41976:12)
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 18 (2 by maintainers)
Commits related to this issue
- fix storybook not compatible w/ compound components for further detail, see https://github.com/storybookjs/storybook/issues/5013 — committed to moira-alert/web2.0 by deleted user 2 years ago
This is a generic error that can come from anywhere. It’s typically a user error when one tries to use a non-component as a react component.
Consider the following two snippets:
If
Buttonis the default export then first is correct. If it’s a named export, then the second is correct. If you accidentally uses the wrong one, you’ll get this error.Getting the same issue, were you able to resolve it?
The issue is still happening, and how can you guys just mark it closed, without a solution?
Confirm this bug. Thank you for your solution!
Having same problem when trying to import class-based components. No solution suggested here worked for me. I’m importing the component file directly (no index.js file) and the default import is always undefined.
I got this error trying to setup storybook v7.2.3 as a new user on a simple demo project. I nearly gave up on storybook but thanks to [abdo99989](https://github.com/storybookjs/storybook/issues/5013#issuecomment-1462563076) I can confirm that switching my components from functional like so fixes the problem:
Fails
Works
Is there a way to make storybook work with functional components?
This happens for me just for functional components, weird issue!
I’ve met this issue not because of bad use of
import/exportbut because of the definition of a static property which somehow mess up with it.RadioGroup.tsx
when importing RadioGroup this way
RadioGroup.stories.tsx
and using static property
Radio:I got the error.
(definition of
Radiocomponent:)but if I import
Radioand use it error disappear:Make sure all your storybook dependencies are using the same version! I was using the following dependencies and had the same issue:
Somehow,
storybookwas updated to7.3.1, during a lockfile refresh of our dependency bot, while the others remained at7.2.3.Manually deleting
node_modules(not sure if necessary), updating the deps to^7.3.1and doing a freshnpm installfixed the issue for me.