-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
[Bug]: Default stories show "Cannot find module [...]" with Storybook (v7) and Gatsby (v5) #21958
Comments
Hello :) I have the same problem. We have upgraded Storybook to 7, followed all guides from docs and here: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#from-version-65x-to-700 And we have exactly the same error when storybook runs: Cannot find module './src/stories/Accordion.jsx' |
I've tried to init clean Storybook with Gatsby 5 using "npx storybook@latest init" and there is the same error: |
Same issue here, is there any workaround? |
Workaround is to downgrade Storybook version to 6 and wait for update from Gatsby side |
pnpm with @tarojs has same issue. |
Hey @shilman @JReinhold @jonniebigodes, I understand that Gatsby is not a priority on Storybook's radar and that you rely on community on fixing things, but it seems that nobody here has the slightest idea where to start with fixing this. Is it a problem with SB? is it a Gatsby problem? As far as I can understand, it's mostly with configuring webpack and that something changed between SB 6 -> 7. It seems that storybook's only public gatsby project failed to update too, looking at the commits on this branch . Can you give any suggestions on where to start looking? It's a bit hard to figure out how things should be, when pretty much out-of-box it just doesn't work. |
Gatsby team would like this to work. It does seem confirmed the issue was introduced on the Storybook side with v7, not the Gatsby side with its v5. I see the new Framework API but its not clear if any previous framework without a plugin will be broken? The main changes I see as possible culprits in the v6 -> v7 migration guide are the framework field and the |
is there any update here? |
this helped me resolve issue #22796 |
@oskari I ran into same issue of "Cannot find module...", with storybook@7.6.17, and managed to solve it. Don't know how it was back in 7.3.2, but currently babel-loader is at index 3 in rules array, not 2. Check it out, maybe you're just updating a wrong rule. Also in your listing, you do this: // Transpile Gatsby module because Gatsby includes un-transpiled ES6 code.
config.module.rules[2].exclude = [
/node_modules\/(?!(gatsby|gatsby-script)\/)/,
]
// Remove core-js to prevent issues with Storybook
config.module.rules[2].exclude = [/core-js/] Looks like the second expression overrides the first one. So you don't actually add the regexp for gatsby modules. Another arcane nuance I found is that you're not allowed to replace the Violating this will actually cause the "Cannot find module..." error. Meaning: // this won't work:
loader.exclude = /node_modules\/(?!(gatsby|gatsby-script)\/)/
// this also won't work:
loader.exclude = [
/node_modules\/(?!(gatsby|gatsby-script)\/)/
]
// this worked for me:
loader.exclude[0] = /node_modules\/(?!(gatsby|gatsby-script)\/)/ Overall, to switch from SWC to Babel in my setup, I had to do following:
webpackFinal: config => {
type Rule = {
use?: Array<string | { loader: string }>
exclude?: Array<string | RegExp>
}
const babelLoader = (config.module?.rules as Rule[])?.find(rule =>
rule.use?.some(use =>
(typeof use === 'string' ? use : use.loader).includes('/babel-loader/')
)
)
if (babelLoader?.exclude) {
babelLoader.exclude[0] = /node_modules\/(?!gatsby|gatsby-script)/
}
return config
}
ERROR in ./node_modules/@storybook/test/dist/index.js 6:69019-69032
Module not found: Error: Can't resolve 'os' in '/path/to/node_modules/@storybook/test/dist'
ERROR in ./node_modules/@storybook/test/dist/index.js 6:69037-69051
Module not found: Error: Can't resolve 'tty' in '/path/to/node_modules/@storybook/test/dist' So in Object.assign(config.resolve.fallback, { os: false, tty: false }) And with that, it finally worked. |
Describe the bug
When setting up storybook v7 to a gatsby v5(?) project that uses custom babel config according to gatsby docs, default stories fail to show and instead show errors like:
or
To Reproduce
System
Additional context
No response
The text was updated successfully, but these errors were encountered: