Chakra Storybook: TypeError "theme.background is undefined" (TypeScript / React)
See original GitHub issueDescription
I recreated this issue in a fresh project, following steps to install the create-react-app
template for Chakra and Typescript per docs, and the Chakra addon and @chakra-ui/icons
also per Chakra docs along with initializing Storybook. Upon booting storybook, it appears that you able to see a component no issue, but when navigating to the docs tabs, The error ‘theme.background is undefined’ apppears, I switch back to the visual, and the error persists. In addition to the example stories that Storybook provides, I made a test component that uses a Chakra component and getting the same result.
Link to Reproduction
https://codesandbox.io/s/musing-monad-mrzmg
Steps to reproduce
A fresh project.
- Run
yarn create react-app my-app --template @chakra-ui/typescript
- Run
npx sb init
- Run
yarn add -D @chakra-ui/storybook-addon
andyarn add @chakra-ui/icons
per Chakra docs on Storybook - Added
@chakra-ui/storybook-addon
to.storybook/main.js
per docs - Created a test component using two Chakra Components, and created a default story for this component.
- Run
yarn storybook
- View a component (Storybook example or
TestComponent
) - Select the
Docs
tab if error did not appear immediately - Switch back to
Canvas
to see error persistence
No other configurations done.
Chakra UI Version
1.8.1
Browser
Firefox 96.0.3
Operating System
- macOS
- Windows
- Linux
Additional Information
@chakra-ui/storybook-addon v1.0.1
Is there supposed to be an extra step to satisfy TypeScript?
Screenshot:
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top GitHub Comments
Finally came back around to this! 😅
This was the solution for me, based on the aliasing from the linked shared by @srt4rulez and the use of
toPath
from the Chakra package main.jsI fixed it for me by adding the alias’ from https://github.com/storybookjs/storybook/issues/16716#issuecomment-1020613602
It seems that https://github.com/storybookjs/storybook/pull/17000 is suppose to fix the issue without a workaround, which is to be released with storybook v6.5.0.