storybook: [Bug]: Failed to load preset: "@storybook/**/preset"
Describe the bug
I completed the storybook auto upgrade to support it’s integration with next
npx storybook@next upgrade --prerelease
- all the relevant storybook packages upgraded to “^7.0.0-beta.53”
- my script tag was successfully changed to
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
I am running a monorepo with yarn workspaces therefore I added the specific path for my next.config.mjs file in my .storybook/main.js file
framework: {
name: '@storybook/nextjs',
options: {
nextConfigPath: path.resolve(__dirname, '../next.config.mjs'),
},
}
when I go ahead and yarn storybook
and get the following error:
Failed to load preset: "@storybook/nextjs/preset"
ERR! Error: Cannot find module '@storybook/nextjs/preset'
To Reproduce
I have “next”: “13.0.2”, and my storybook version was
"@storybook/addon-actions": "^6.5.13",
"@storybook/addon-essentials": "^6.5.13",
"@storybook/addon-interactions": "^6.5.13",
"@storybook/addon-links": "^6.5.13",
"@storybook/builder-webpack5": "^6.5.13",
"@storybook/manager-webpack5": "^6.5.13",
"@storybook/react": "^6.5.13",
"@storybook/testing-library": "^0.0.13",
run npx storybook@next upgrade --prerelease
- all storybook packages successfully
- scripts successfully changed
- .storybook/main.js file changed too
path = require('path');
module.exports = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
staticDirs: ['../public'],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
'@chakra-ui/storybook-addon',
],
framework: {
name: '@storybook/nextjs',
options: {
nextConfigPath: path.resolve(__dirname, '../next.config.mjs'),
},
},
webpackFinal: async (config) => {
config.resolve.alias = {
...config.resolve.alias,
'~': path.resolve(__dirname, '../src/'),
'next-i18next': 'react-i18next',
};
config.resolve.extensions.push('.ts', '.tsx');
const fileLoaderRule = config.module.rules.find((rule) => rule.test && rule.test.test('.svg'));
fileLoaderRule.exclude = /\.svg$/;
config.module.rules.push({
test: /\.svg$/,
enforce: 'pre',
loader: require.resolve('@svgr/webpack'),
});
return config;
},
docs: {
autodocs: true,
},
};
my error:
@storybook/cli v7.0.0-beta.53
WARN Failed to load preset: "@storybook/nextjs/preset"
ERR! Error: Cannot find module '@storybook/nextjs/preset'
System
No response
Additional context
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 10
- Comments: 31 (13 by maintainers)
@re-thc Please delete your
yarn.lock
file and reinstall all dependencies. This should fix the issue.Getting the same error when I run
npx storybook build
inside an app inside a Nx monorepo!I’d like to reopen this issue. I’m also using yarn workspaces. In my case,
@storybook/core-common
is at the root (node_modules/@storybook/core-common
) and the nextjs preset is in a workspace’s node_modules folder (apps/web/node_modules/@storybook/nextjs
) (for some reason the@storybook/nextjs
package is not hoisted to the root).@storybook/core-common
tries to load@storybook/nextjs/preset.js
(at this line), but because it’s in a child node_modules folder, it can’t find it.The solution imo would be to add a “cwd” argument to the
loadPreset
andinteropRequireDefault
functions, and then userequire.resolve
to resolve the path relative to the workspace where.storybook/main.ts
is located.e.g. (in
interopRequireDefault
):If you’re in the same situation this is a workaround:
I think the “Remove .yarn.lock” and “Use resolutions” workarounds are sometimes working because Yarn might then decide to hoist
@storybook/nextjs
to the root level.I’m getting
on a new project…
EDIT: Fixed by adding the
--use-pnp
flag forinit
, whoops.Yes, yarn workspaces. Found the eventual workaround by deleting everything in
.yarn/cache
as well as all thenode_module
directories and re-installing fresh.Hi ,
I got the same issue, using a yarn 3 monorepo and storybook 7.0.18 with most of storybook deps hoisted at the root but not “@storybook/vue3-webpack5” package which is located in /root/packages/vue3-project/node_modules because i have mixed vue2 and vue3 projects and storybooks…
when my config is
framework: '@storybook/vue3-webpack5',
i got the following stack when running sb dev
the fix
resolve the issue when running sb dev , but when i try sb build i got the following stack
so i can’t publish the storybook 😢
I have the issue on 7.0.5 - Storybook inside a mono repo. The error must be related to some dependency conflicts because it randomly appears again. After removing the cache and re-install the issue persists: https://github.com/dohomi/tamagui-kitchen-sink
Same issue with
Next 14.1.12, Yarn 4.11, storybook 8.0.5
i did delete my yarn.lock file and reinstall all dependencies
I have
@storybook/nextjs 8.0.5
as well.~Is this the 8 version of Vite problem?~
If I do it in
pnpm
, the problem disappearsMy storybook config
Bug affects the following issue: https://github.com/storybookjs/storybook/issues/21710#issuecomment-1499467835
I had the same problem in a Yarn 3 monorepo with workspaces. Solved it by setting the following in the package:
That way nothing gets hoisted for that package. Not the best solution, but at least it works.
@YarnSh39 The Storybook types are a bit too strict in my opinion, the code actually does work. You can use
as any
to fix it:Can you also refresh your
yarn.lock
. It seems, that for some reason conflicting/outdated dependencies are installed. In the above repro the issue was fixed by updating theyarn.lock
file.Same issue here. It was working some beta versions ago but updating to the latest broke it.
Can you install the package
@storybook/nextjs
and see whether the error goes away?