-
Notifications
You must be signed in to change notification settings - Fork 27.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
with-storybook doesn't work without React import #16431
with-storybook doesn't work without React import #16431
Comments
I'll look into this issue. |
You need to create a Next.js custom babel config with the default config so storybook uses that config.
{
"presets": ["next/babel"],
"plugins": []
} references: |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Next.js automatically imports React so you don't have to write
import React from 'react'
in every single source file. Thewith-storybook
example works well with that import, but when it is removed, it doesn't and throws aReact is not defined
error.To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
import React from 'react'
line and run the storybook again.React is not defined
.Expected behavior
Just like the rest of Next.js, the storybook should work without having to import React explicitly.
Screenshots
N/A
System information
Additional context
Storybook's FAQs actually documents this exact issue - see https://storybook.js.org/docs/react/workflows/faq#i-see-referenceerror-react-is-not-defined-when-using-storybooks-with-nextjs
But adding the recommended
babel-plugin-react-require
plugin doesn't solve the issue, as it seems to conflict (or perhaps overwrite?) with Next.js' own Babel configuration. And most discussions around this issue seem to be outdated (they don't work) with the latest v6 release of Storybook.The text was updated successfully, but these errors were encountered: