Discussion of React version compatibility issues in a monorepo with workspaces and solution using Yarn v3
30 replies
Last updated: Oct 4, 2022
M
Hi, I wonder if anyone experienced the same issue? I can not recall when exactly it appeared but the last 2 days I could not run the studio. I have reinstalled node_modules but it has not solved the issue.
Aug 25, 2022, 10:52 AM
M
if relevant - I have the
"react": "^18.2.0"
Aug 25, 2022, 10:54 AM
K
Is this React version in the Sanity project or yours?
Aug 25, 2022, 10:57 AM
M
both
Aug 25, 2022, 10:57 AM
M
Hi
user F
, in sanity proj I use react 18 as peerDependenciesAug 25, 2022, 10:58 AM
K
Are you using v2 or v3?
Aug 25, 2022, 10:59 AM
M
@sanity/cli version 2.31.0
Aug 25, 2022, 11:01 AM
K
So in my v2 Sanity project, I have React as a dependency, not a peer dep, and it’s v17. 😄
Aug 25, 2022, 11:02 AM
M
I get the following when running the studio but it was not an issue before 🙂
Aug 25, 2022, 11:02 AM
K
Right. I think this is the situation.
Aug 25, 2022, 11:03 AM
M
Yes, but it was not breaking any functionalities before for me. Same here: https://github.com/sanity-io/sanity/issues/3456
Aug 25, 2022, 11:05 AM
K
Can you install it as a main dep instead of peer?
Aug 25, 2022, 11:07 AM
M
yes yes ☺️ i’m on it
Aug 25, 2022, 11:07 AM
M
i did so but it did not fix the problem
Aug 25, 2022, 11:07 AM
M
now i downgraded to react 17 and it fixed the problem
Aug 25, 2022, 11:08 AM
M
it’s strange because before i could run it with react 18 even though i had the warnings
Aug 25, 2022, 11:08 AM
K
Fair enough. 😅
Aug 25, 2022, 11:09 AM
M
Thank you for the help,
user F
☺️☺️Aug 25, 2022, 11:09 AM
M
Maybe it cam with the latest sanity update to v2.31idk
☺️
☺️
Aug 25, 2022, 11:09 AM
M
looking forward to sanity to support react 18 🙂
Aug 25, 2022, 11:10 AM
J
Re: React 17/18 issues in SanityIf you’re still dealing with these kind of issues in a monorepo with workspaces, one of my super duper smart colleagues found a solution that works with yarn v3.
This way I can have react 18 in my nextjs app and keep sanity on 17!
"installConfig": { "hoistingLimits": "workspaces" },
Sep 8, 2022, 9:42 AM
Thank you for this,
user E
! Any ideas on how to pull this off with Lerna / Turborepo?Sep 26, 2022, 12:26 PM
J
I don’t think lerna/turborepo should have an influence on this, as that’s more about concurrency,scripts execution and not really hoisting/installing packages I believe?
Sep 26, 2022, 1:09 PM
J
Matter of fact, the project I used as an example is a turborepo monorepo!
Sep 26, 2022, 1:10 PM
So it’s just a matter of adding the above and installing with Yarn? 😄
Which Yarn version are y’all using?
Which Yarn version are y’all using?
Sep 26, 2022, 1:12 PM
J
root
package.jsonlooks like this
{ "name": "root-name", "private": true, "workspaces": [ "apps/*", "packages/*" ], "scripts": { "build": "turbo run build", "dev": "turbo run dev --parallel", "lint": "turbo run lint", "clean": "turbo run clean --parallel", "format": "turbo run format --parallel", "type-check": "turbo run type-check" }, "devDependencies": { "@types/prettier": "^2.7.0", "prettier": "^2.7.1", "rimraf": "^3.0.2", "turbo": "^1.4.3" }, "packageManager": "yarn@3.2.0" }
Sep 27, 2022, 8:23 AM
J
Running on node 16.17.0 with asdf and yarn on 3.2.0
Sep 27, 2022, 8:23 AM
J
and then in
apps/cms/package.jsonwe’ve got this
{ "name": "cms-name", "installConfig": { "hoistingLimits": "workspaces" }, "scripts": { "dev": "sanity start", "start": "sanity start", "test": "sanity check", "build": "sanity build dist -y", "clean": "rimraf .turbo && rimraf node_modules && rimraf dist", }, ...deps and devdeps here }
Sep 27, 2022, 8:25 AM
J
and last but not least, in the root we have
.yarnrc.ymllooking like this
nodeLinker: node-modules plugins: - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs spec: '@yarnpkg/plugin-interactive-tools' - path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs spec: '@yarnpkg/plugin-typescript' - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs spec: '@yarnpkg/plugin-workspace-tools' yarnPath: .yarn/releases/yarn-3.2.0.cjs
Sep 27, 2022, 8:26 AM
J
Ahh great mate! I know the frustration so I can imagine the relieve you have right now 😄!
Oct 4, 2022, 8:12 AM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.