Impossible to use `sanity install <plugin-name>` when using Yarn 2
See original GitHub issueDescribe the bug
In my project, I recently migrated to Yarn 2 (without PnP, so still using node_modules
). It is a Yarn Workspaces monorepo and everything works fine. However, I just discovered than since then, I am unable to install plugins for Sanity with the official CLI.
Unfortunately, I can’t supply the code here as it is a private repo. I could do a minimal reproduction repo if necessary, but the error is pretty self-explanatory:
➜ yarn sanity install content-calendar
✖ Resolving dependencies
✖ An unexpected error occurred: "Unknown token: { line: 3, col: 2, type: 'INVALID', value: undefined } 3:2 in /Users/my-username/Projects/my-repo/yarn.lock".
✖ Resolving dependencies
Error: Command failed :(
at ~/Projects/my-repo/node_modules/@sanity/cli/bin/sanity-cli.js:3260:2554
My guess on the issue is that the Yarn version bundled with the CLI completely ignores the Yarn 2 installation in the repository. Since the yarn.lock
file structure changed in Yarn 2 (see this link for more info), I think that the bundled Yarn package in the CLI just fails on reading the lockfile.
To Reproduce
- Have a working Sanity Studio
- Migrate to Yarn 2:
yarn set version berry
and the following content in.yarnrc.yml
:nodeLinker: node-modules yarnPath: .yarn/releases/yarn-berry.cjs
- Run
sanity install <my-plugin-name>
Expected behavior
The plugin should be installed without any error.
Which versions of Sanity are you using?
@sanity/cli 2.1.4 (up to date)
@sanity/base 2.1.4 (up to date)
@sanity/cli 2.1.4 (up to date)
@sanity/components 2.1.4 (up to date)
@sanity/core 2.1.4 (up to date)
@sanity/default-layout 2.1.4 (up to date)
@sanity/default-login 2.1.4 (up to date)
@sanity/desk-tool 2.1.4 (up to date)
@sanity/ui 0.32.4 (up to date)
@sanity/vision 2.1.4 (up to date)
What operating system are you using? MacOS 11.1 / Google Chrome 87
Which versions of Node.js / npm are you running?
➜ npm -v && node -v
6.14.8
v12.20.0
➜ yarn -v
2.4.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:10
- Comments:5 (1 by maintainers)
I have the same problem. Our repo is public so you can test it here: https://github.com/Alv-no/alv-website
Currently I’m opting out of PnP for the Sanity Studio package in a monorepo, following Yarn’s instruction: https://yarnpkg.com/getting-started/recipes#hybrid-pnp--node_modules-mono-repo
There’s no need to bother with
sanity install
. You can just manually add the plugin name tosanity.json
afteryarn add
.