You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Its not a specific error but depending on how I manage my imports storybook seems to have problems loading stories and resolving imports.
Often times my I get errors telling me I try to call styled() with undefined which cannot be true because in my project every styled call directly follows constant definition.
For example the following component and story currently creates issues:
component:
// src/shared/ui/typography/heading.tsximportstyledfrom"styled-components";// Core only exports plain typescript files and also does not export anything outside of its directory so its not the issue.import{sizeToPixel}from"core";exporttypeHeadingProps={level?: "h1"|"h2"|"h3"|"h4"|"h5"|"h6";children: string;};exportconstHeading=styled.h1.attrs((props: HeadingProps)=>({as: props.level,}))<HeadingProps>` font-family: inherit; font-size: ${props=>sizeToPixel(props.level,["h1","h2","h3","h4","h5","h6"],[3.2,2.8,2.2,1.8,1.4,1.2],"h1")+"em"};`;Heading.displayName="Heading";exportconstTitle=styled(Heading).attrs({level: "h1"})``;Title.displayName="Title";exportconstSubtitle=styled(Heading).attrs({level: "h2"})``;Subtitle.displayName="Subtitle";
And my story:
import{Meta,Story}from"@storybook/react";importReactfrom"react";// This is the actual heading.tsx file I have also tried shared/ui which creates other problemsimport{Heading,HeadingProps}from"shared/ui/typography/heading";exportdefault{title: 'Shared/Typography/Heading',component: Heading,}asMeta;constTemplate: Story<HeadingProps>=(args)=><Heading{...args}/>;exportconstHeading1=Template.bind({});Heading1.args={level: "h1",children: "Lorem ipsum dolor sit amet",};
Storybook is not able to display this story the console prints the following warning:
Unexpected error while loading ./stories/shared/Heading.stories.tsx: ReferenceError: Cannot access 'Heading' before initialization
I am using the CRA typescript template with styled-components.
I dont use any default exports in my files.
I have also additionally used madge to check for any circular dependencies but it does not show any.
If I use my components inside my app it just works normally.
So I think there is an issue with storybooks build system.
Describe the bug
Its not a specific error but depending on how I manage my imports storybook seems to have problems loading stories and resolving imports.
Often times my I get errors telling me I try to call
styled()
with undefined which cannot be true because in my project everystyled
call directly follows constant definition.For example the following component and story currently creates issues:
component:
And my story:
Storybook is not able to display this story the console prints the following warning:
I am using the CRA typescript template with styled-components.
I dont use any default exports in my files.
I have also additionally used
madge
to check for any circular dependencies but it does not show any.If I use my components inside my app it just works normally.
So I think there is an issue with storybooks build system.
To Reproduce
I dont know
System
Additional context
CRA Typescript
Styled Components
In general when Im using storybook now I feell like playing the lottery when definining exports/imports and writing stories.
The text was updated successfully, but these errors were encountered: