-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Storybook broken when no React import with new JSX transform from react > 16.14.0 #12881
Comments
Problem is with This worked for me: // main.js
module.exports = {
// ...
babel: async (options) => ({
...options,
presets: [
...options.presets,
[
'@babel/preset-react', {
runtime: 'automatic',
},
'preset-react-jsx-transform' // Can name this anything, just an arbitrary alias to avoid duplicate presets'
],
],
}),
}; |
What are the implications of building this option into storybook? Would it be a breaking change? |
This depends on how Edit I lied.. I took the few seconds required to downgrade my
So it appears that this would be a breaking change unless you made it configurable and defaulted to the |
Create React App, Next.js and Gatsby have already supported new JSX transform. https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#create-react-app Here is a Next.js implementation example.
|
Looks like this is also breaking our CI on CRA4:
|
Matthew,
In regards to a computer/ laptop that’s not going to be an option mine recently broke, and on anyone who else is involved could be storybooks.
But I look forward to our call, and the savings plan is right, just don’t understand why I have so many accounts open
Richard Voyles
Richard Voyles
… On Oct 23, 2020, at 11:10 AM, RookY2K ***@***.***> wrote:
Problem is with @storybook/react. It adds the @babel/preset-react preset without the requisite runtime: 'automatic' option set.
This means you cannot just add the @babel/preset-react to the babel property in your main.js.
A hacky workaround that worked for me:
// main.js
module.exports = {
// ...
babel: async (options) => {
const reactPresetIndex = options.presets.findIndex((preset) => preset.includes('preset-react'));
const presetsWithoutReact = [
...options.presets.slice(0, reactPresetIndex),
...options.presets.slice(reactPresetIndex + 1),
];
return {
...options,
presets: [
[
***@***.***/preset-react', {
runtime: 'automatic',
},
],
...presetsWithoutReact
],
};
},
};
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Jeepers creepers!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.1.0-alpha.30 containing PR #12899 that references this issue. Upgrade today to the
Closing this issue. Please re-open if you think there's still more to do. |
NOTE: this is hopefully fixed in 6.1 ☝️ . We need to get it back into the stable release, but are having problems with repros in CI. In the meantime if people can upgrade to 6.1 to test it out, please give it a try and report back:
If it doesn't work right away, try removing & regenerating lockfiles. |
Upgrading to latest alpha fixed my issue. Will now patiently wait until the fix gets merged into the stable release. Thanks! |
I have a similar problem in browser console:
My packages versions: {
"@storybook/addon-docs": "^6.1.0-alpha.31",
"@storybook/react": "^6.1.0-alpha.31",
"react": "^17.0.1",
"react-dom": "^17.0.1"
} main.js file: module.exports = {
stories: ['../src/components/**/*.stories.tsx'],
addons: ['@storybook/addon-docs'],
webpackFinal: (config) => {
config.resolve.plugins.push(new TsconfigPathsPlugin());
return config;
}
}; This problem exists only after production build. No problem in "start-storybook" mode Edit I removed @storybook/addon-docs from the list of addons and the error was removed. Apparently, the reason for the error in this addon |
I'm getting the same error that @DiFuks is getting, I've created a small repo where you can reproduce this bug: https://github.com/nandosangenetto/storybook-bug-repro I've tried to remove all addons, as @DiFuks did, but it didn't work. What is odd is that it works when I run |
@DiFuks are you also using styled components? |
I've opened a separate issue for this @NandoSangenetto @DiFuks #12952 |
No, I don't use styled-components. Also, I commented out the addons again. And the error hasn't gone away. So, the problem is @storybook/react |
fixed for us on v6.1.0-rc.0 |
I'm closing this and will follow up on #12952 |
This doesn't seems to work with Yarn 2. I am not getting the runtime: 'automatic', even with React 17 and react/jsx-runtime being present and that is probably because of the paths used may not be working with Yarn (Yarn 2 does not store files in node_modules but zipped in its .yarn/cache instead). |
@shilman |
@gaetanmaisse any thoughts on yarn 2 compat? |
#12899 Added support for new JSX transform and it is included in 6.1 release, however implementation depends on file location with node_modules that prevents it from working with yarn pnp. CRA uses resolve without specifying paths and it works. Is there something special in storybook setup? |
For any sorry soul who wandered here to fix that pesky config.resolve.alias = {
// react: require.resolve('react'),
'react/jsx-runtime': require.resolve('react/jsx-runtime'),
'react-dom': require.resolve('react-dom'),
'react-hot-loader': require.resolve('react-hot-loader'),
'styled-components': require.resolve('styled-components'),
} Which actually required me to comment out the react alias. I'm not quite sure why, but it seems to have conflicted with the jsx runtime. Interesting behavior, indeed. Hopefully it now works. |
Thank you for this! I banging my head against a wall for 2 days with this issue and this was the resolution (commenting out the previously defined react alias when adding the alias for jxs-runtime) |
I'm pretty sure the fix here was only for the Preview, not the Manager. I've written a custom addon that uses React in the Manager and ran into the same problem here. |
@jam-awake I'm having the same issue, did you find a solution? |
@sigginjals Yeah. I needed to add modul.exports = {
...
managerWebpack: (c) =>
setReactRuntimeAutomatic(c),
};
const modifyConfigModuleRules = (fn) => (config) => {
return {
...config,
module: {
...config.module,
rules: fn(config.module.rules),
},
};
};
const setReactRuntimeAutomatic = modifyConfigModuleRules((rules) => {
return rules.reduce((acc, next) => {
if (
isNonNullObjectWithField(next, "use") &&
isNonNullArray(next.use) &&
next.use[0] &&
isNonNullObjectWithField(next.use[0], "options") &&
isNonNullObjectWithField(next.use[0].options, "presets")
) {
const presets = next.use[0].options.presets;
next.use[0].options.presets = presets.reduce((pAcc, pNext) => {
if (
typeof pNext === "string" &&
pNext.includes("manager-webpack5") &&
pNext.includes("preset-react")
) {
pAcc.push([pNext, { runtime: "automatic" }]);
} else {
pAcc.push(pNext);
}
return pAcc;
}, []);
}
acc.push(next);
return acc;
}, []);
}); |
Hi @shilman, unfortunately this is still an issue for Storybook Manager (using Storybook v7). If React is not explicitly imported when creating a custom panel, the whole app breaks. |
I'm using Vite and @vitejs/plugin-react helped me.
|
Describe the bug
React 16.14.0 introduced the new JSX transform, which means you don't have to import React when when you use JSX anymore. Sadly, I am not able to remove any import from the components/stories used in storybook. Did I miss something ? 🤔
To Reproduce
Steps to reproduce the behavior:
npx create-react-app my-app && cd my-app
npx sb init
npm run storybook
import React from 'react'
from the.stories.js
or.js
file of one component and go to the story of this component (you might need to disable thereact/react-in-jsx-scope
eslint rule)React is not defined
Expected behavior
A beautiful and shiny story ✨
Screenshots
System
I also tried with storybook
6.1.0-alpha.28
, same resultsThe text was updated successfully, but these errors were encountered: