Closed justintemps closed 1 year ago
We're having a similar issue with yarn v3 workspaces (no plug and play), where one package depends on Storybook v6 and the other on Storybook v7.
The storybook
package get's hoisted to the top level node_modules
, whereas the @storybook/react-webpack5
remains in the package node_modules
.
monorepo root
node_modules
@storybook
(no react-webpack5 package here)
storybook ("version": "7.0.0-beta.29")
packages
our-library
node_modules
@storybook
react-webpack5 ("version": "7.0.0-beta.29")
(no storybook package here)
That causes an error if you try to run yarn storybook
in our-library
WARN Failed to load preset: "@storybook/react-webpack5/preset"
ERR! Error: Cannot find module '@storybook/react-webpack5/preset'
ERR! Require stack:
ERR! - /monorepoRoot/node_modules/@storybook/core-common/dist/index.js
ERR! - /monorepoRoot/node_modules/@storybook/telemetry/dist/index.js
ERR! - /monorepoRoot/node_modules/@storybook/cli/dist/generate.js
ERR! - /monorepoRoot/node_modules/@storybook/cli/bin/index.js
ERR! - /monorepoRoot/node_modules/storybook/index.js
I'll be honest, I'm not sure if this is something that is officially supported. I've had trouble in the past with multiple different storybook versions in packages in a monorepo. Is there any way to keep storybook packages from being hoisted? I know there used to be a way with older versions of yarn, but I'm not sure about recent versions or pnpm. But I'll try taking a look to see if I can figure something out.
@IanVS may be this could work for older versions of Storybook that use webpack 4? https://github.com/webpack/webpack/issues/5087#issuecomment-1157689388
I've looked at this today and I'm starting to think that it might be an unsolvable problem and that the best way to avoid it for now is just not to try to build the two projects together. That's annoying, because before I was able to set styles for the same component in two different storybook projects at the same time, but I don't see a way around it until Wingsuit upgrades to SB 7 or at least to Webpack 5.
I have the same problem with @storybook/react-vite/preset
.
Storybook v7.0.0-beta.34
Vite v4.0.0
Yarn 3.3.1 with workspaces (no PnP)
I have same too...
Storybook v7.0.0-beta.36
Vite v4.0.0
build management: lerna
I eventually worked around this by installing the two Storybook projects separately. My package.json
ended up looking like this:
"scripts": {
"clean:deps": "rm -rf pnpm-lock.yaml node_modules && pnpm -r exec rm -rf node_modules",
"storybook7:install": "pnpm clean:deps && pnpm --filter storybook7... install",
"storybook6:install": "pnpm clean:deps && pnpm --node-linker=hoisted --filter storybook6... install"
}
where storybook6
and storybook7
are two different Storybook packages in a monorepo. You obviously need to build the projects separately also and it's not possible to work on both at once, but I don't think there's a better solution for now.
For future reference, I managed to solve my problem using Yarn's no-hoist option - https://yarnpkg.com/configuration/yarnrc#nmHoistingLimits This is less ideal, but it works...
@IanVS given that this issue probably doesn't have an official solution, at least not without upgrading older versions of Storybook or at least using them with Webpack5, but that it does have a workaround, perhaps I should close this issue? Happy to leave it if it's useful to have open.
I don't think there's really anything we can do to support this any better than the workarounds that have been identified, so yeah let's close it out. Lord knows we have enough open issues. 😅
Thanks for bringing it up and for sharing the workarounds!
My root package.json had
{
...
"nohoist": [
"@storybook",
"**/@storybook",
"**/@storybook/**"
]
...
}
Running yarn
would install it to the right spot, but running npx storybook upgrade
would cause the no-hoisted @storybook packages to get hoisted and install to root.
I already had the following in my main.ts
which when output resolve to the proper path.
/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, 'package.json')));
}
Finally, I did something we are all familiar with... tossing our hands in the air and deleting the lockfiles and node_modules out of frustration and seeing that it worked.
Describe the bug
I have a monorepo with two Storybook packages. One is a React package that I just migrated to
storybook@next
and the other is a Wingsuit project for twig that usesstorybook@6.5.15
.I'm using pnpm to manage dependencies and turborepo to orchestrate tasks.
Before migrating my react package to
@next
in anticipation of version 7, both projects were on the same version of both Storybook and webpack and everything worked fine. After I bumped the React version, however, I can only ever get one of the packages to build.It seems like the Wingsuit/Twig project (which uses
storybook@6.5.15
will only build if I install dependencies withpnpm install
withnode-linker = hoisted
set in.npmrc
. However, in that case, the React package seems unable to find its own hoisted dependencies:Conversely, I can get the React package (which uses
storybook@next
) to build by installing dependencies normally without anything set in.npmrc
, but the Twig package throws build errors:I think this is because Webpack 4 resolves loaders incorrectly unless it's hoisted, but I can't figure out why hoisting should break the
storybook@next
dependency graph.To Reproduce
System
Additional context
No response