Yarn 2: Support Yarn v2 "Berry"
See original GitHub issueDescribe the bug
If you use Yarn v2, then you can’t add Storybook to a simple Create React App, it crashes.
See https://github.com/yarnpkg/berry/issues/592#issuecomment-575895264
And the output here:
To Reproduce
The following process is used in the workflow to reproduce this bug:
- Install yarn v2: https://next.yarnpkg.com/getting-started/install
yarn dlx create-react-app my-cra && cd my-cra
to init a crat react appyarn dlx -p @storybook/cli sb init
to init storybook, but it fails here- Then I would do
yarn storybook
and that would be it… ideally…
Expected behavior
Success
Screenshots
Error: Cannot find module 'commander'
Require stack:
- /Users/vincent/.yarn/berry/cache/@storybook-cli-npm-5.3.6-c196adf18e-1.zip/node_modules/@storybook/cli/bin/generate.js
- /Users/vincent/.yarn/berry/cache/@storybook-cli-npm-5.3.6-c196adf18e-1.zip/node_modules/@storybook/cli/bin/index.js
Require stack:
- /Users/vincent/.yarn/berry/cache/@storybook-cli-npm-5.3.6-c196adf18e-1.zip/node_modules/@storybook/cli/bin/generate.js
- /Users/vincent/.yarn/berry/cache/@storybook-cli-npm-5.3.6-c196adf18e-1.zip/node_modules/@storybook/cli/bin/index.js
at Proxy.module_1.Module._resolveFilename (/private/var/folders/2g/yhlpschd00n71jykx6bgbp1w0000gn/T/tmp-69185QMHt9oBf5169/dlx-69185/.pnp.js:18118:54)
at Proxy.module_1.Module._load (/private/var/folders/2g/yhlpschd00n71jykx6bgbp1w0000gn/T/tmp-69185QMHt9oBf5169/dlx-69185/.pnp.js:18001:40)
at Object.<anonymous> (/Users/vincent/.yarn/berry/cache/@storybook-cli-npm-5.3.6-c196adf18e-1.zip/node_modules/@storybook/cli/bin/generate.js:1)
at Generator.next (<anonymous>)
System:
➜ npx -p @storybook/cli@next sb info
Environment Info:
System:
OS: macOS 10.15.2
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Binaries:
Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
Yarn: 2.0.0-rc.23 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.15.3/bin/npm
Browsers:
Chrome: 79.0.3945.117
Firefox: 71.0
Safari: 13.0.4
Additional context Trying to make Storybook work with yarn v2
Issue Analytics
- State:
- Created 4 years ago
- Reactions:30
- Comments:26 (20 by maintainers)
Top Results From Across the Web
Migration | Yarn - Package Manager
A step-by-step and in-depth migration guide from Yarn 1 (Classic) to Yarn 2 (Berry).
Read more >State of Yarn 2 (Berry) in 2021 - Hao's learning log
Yarn 2, aka Berry, was announced back in April 2019, it was a pretty big deal at the time. I've moved 2 clients...
Read more >Yarn 2 — the future of package managers for JavaScript? - Snyk
You can find the community repository on GitHub at: https://github.com/yarnpkg/berry. Why did we need a new Yarn version? Yarn 2 ticks a quite...
Read more >Migrating to Yarn 2 - Heroku Dev Center
This article is intended to help current Heroku users migrate from Yarn 1 to Yarn 2. Apps being migrated should already be using...
Read more >Migrating our Monorepo to Yarn 2 | DoltHub Blog
It took us some extra steps to make Yarn 2 work with our monorepo and ... web % npm install -g yarn web...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
With Storybook
6.0.0-alpha.6+
SB & Yarn 2 are working together for simple config, as in repro repo provided by @crubier 🎉I still need to work on:
yarn dlx -p @storybook/cli sb init
works, to have out of the box support:@storybook/preset-create-react-app
. it’s currently resolving react-script innode_modules/.bin/
directory, so I need to add one more check for SB PnP user and access webpack config file directly in the .zip file with PnP API.Finding a way of adding examples with Yarn 2 inside SB monorepo. Maybe creating some GitHub actions as it is done on Yarn 2 repo can be a good idea because it really mimics the users’ behaviors: https://github.com/yarnpkg/berry/blob/master/.github/workflows/e2e-jest-workflow.yml
Handle
.storybook/preview.js
file properly . See https://github.com/storybookjs/storybook/issues/10094@ndelangen For the cache folder, I put it in
node_modules/.cache/@storybook
for now. An enhancement issue has been created by @arcanis in Yarn Org https://github.com/yarnpkg/berry/issues/918 to discuss the usefulness, pros, and cons of creating and maintaining acache
pkg in the Yarn org. If it ends on the creation of a such package we will surely use it instead of our custom resolve-path-in-sb-cache.js.Current situation about the compatibility with Yarn 2 (a.k.a Berry)
@crubier created a repo explaining how to make SB works with Yarn Berry: https://github.com/crubier/yarnv2-storybook, the workaround is to:
@storybook/core
, for details see https://next.yarnpkg.com/cli/unplug ->yarn unplug @storybook/core
node_modules
folder to be able to create SB Babel cache folder ->mkdir node_modules
Based on this repo and comments, multiple points need to be addressed to make SB works with Yarn Berry out of the box. There are my thoughts about that:
It looks like
@storybook/core
needs to be unplugged because it writes something inside itself. This is working with classical/legacy yarn becausenode_modules/@storybook/core
is a folder with writable rights. In Yarn Berry, packages are read-only so no more writings allowed:So we need to find which part of
@storybook/core
is writing something and update this behavior. Sadly for us@storybook/core
is (one of) the last packages still in JS.As there is no
node_modules
folder anymore, we need to find another place to put SB Babel cache. The file managing this is https://github.com/storybookjs/storybook/blob/next/lib/core/src/server/common/babel-cache-preset.js and it should be pretty easy to fallback/move to another cache folder. However, I didn’t find any wide used convention for where should be the cache folder for now (some package like Babel have a fallback to os.tmp(), webpack has changed it here…), so I think we need to discuss that.Update the base webpack config to include Plug’n’Play resolver if the user is using Yarn Berry (in a more global point of view is using Plug’n’Play i.e. there is a
pnp.js
file in its project)OR
Create a preset to handle this out of
@storybook/core
as it is affecting only a part of SB users. Something like what @igor-dv and @crubier started there: https://github.com/storybookjs/presets/pull/18 (which is only working for TS users).My personal opinion is that we should consider adding the Plug’n’Play resolver in SB core as Yarn Berry is now the “stable” version (yarn as we are used to is now legacy). More and more SB users will be using Yarn Berry and SB should work with it without any additional setup. According to https://github.com/nodejs/docker-node/issues/1180, Yarn Berry will/should be the default version ship with Node 14 Docker Image.
Here is a link of Introducing Yarn 2 article written by its main maintainer.
Any feedback on all this is welcome! @crubier @igor-dv @ndelangen @shilman and anyone else 😃