-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 v7 nextjs - Importing from another lib causes Module not found: Error: Can't resolve error #16208
Comments
Hi @victorcarvalhosp ! Can you please share your |
Hi @mandarini, it's the default one that was generated:
|
Thank you very much @victorcarvalhosp ! I will investigate this issue this week. I noticed such a regression in the vite builder too, maybe it's related. |
@mandarini Thanks for looking into this! I have encountered a similar issue as well, and my attempts of "trying to be smart" by manually adding aliases through the In my example, the storybook sits as its own package and it's trying to load all stories and MDX files from its sister packages. The directory structure:
The export const rootMain: StorybookConfig = {
stories: ['../../**/*.stories.mdx', '../../**/*.stories.@(ts|tsx)'],
addons: ['@storybook/addon-a11y', '@storybook/addon-essentials', '@storybook/addon-interactions'],
staticDirs: ['../public'],
webpackFinal: async (config) => {
if (config.resolve) {
config.resolve = {
...config.resolve,
alias: {
...(config.resolve.alias ?? {}),
'@my-library': path.resolve(__dirname, '../../my-library/src/index.ts'),
},
};
}
return config;
},
framework: {
name: '@storybook/nextjs',
options: {
nextConfigPath: '../../site/next.config.js',
},
},
docs: {
autodocs: true,
},
};
export default rootMain; |
This PR should fix this issue! |
In the meantime, you can check these docs to help you resolve your issue: https://storybook.js.org/docs/react/builders/webpack#typescript-modules-are-not-resolved-within-storybook |
I am closing this, since it turned out to be a third-party issue. Once the next version of Storybook is released which contains the fix, your issue should be resolved, without any extra settings from your part. Just your plain |
Thanks for the very helpful info @mandarini :) you've saved me one too many times: for some reason I remember seeing that doc page on Storybook but could never find it again. p/s: For those who can't get the default usage to work, i.e.: new TsconfigPathsPlugin({
extensions: config.resolve.extensions,
}) ...manually resolving to the new TsconfigPathsPlugin({
extensions: config.resolve.extensions,
configFile: path.join(process.cwd(), './tsconfig.base.json'),
}) |
Ha, that's so good to hear @terrymun ! :D Once the Storybook PR gets merged, you will not need to do these manual settings!! :) :) The credit goes to the Storybook team and @valentinpalkovic for the quick fix!!! |
@mandarini I realized that I have no |
No, it works with I tried it in my example reproduction repository and it works as expected! |
Thank you very much @mandarini ! |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
I have two libs: "layout" and "families: - and configured storybook for them using the nextjs version of the storybook generator: https://nx.dev/packages/storybook/documents/storybook-7-setup
It works fine at the beginning, but as soon as I try to create a new story in the "families" project, that relies on one component that comes from "layout" lib then storybook doesn't work anymore and throw the following error:
Running the project outside storybook everything works fine.
Expected Behavior
Storybook should work fine when there's some component that imports some component from another library in the same monorepo.
GitHub Repo
No response
Steps to Reproduce
nx g @nrwl/next:lib layout
nx g @nrwl/next:lib families
2-Then configure storybook for both:
nx g @nrwl/storybook:configuration layout --storybook7Configuration --storybook7UiFramework=@storybook/nextjs
nx g @nrwl/storybook:configuration families --storybook7Configuration --storybook7UiFramework=@storybook/nextjs
Now create some component in the layout lib, and import it on families project.
The component can be as basic as this:
on layout:
on families:
Then run storybook in the families lib and this error will happen:
Nx Report
Failure Logs
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: