Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mismatching react version with react 17 #3167

Closed
ozanmanav opened this issue Apr 29, 2021 · 5 comments
Closed

Mismatching react version with react 17 #3167

ozanmanav opened this issue Apr 29, 2021 · 5 comments

Comments

@ozanmanav
Copy link

ozanmanav commented Apr 29, 2021

Hello. When will the master branch of the formic repo be released? Now, the old react version in version 2.2.6 causes problems with monorepo.

When I check the 2.2.6 package.json it seems used react 16.x version. But we're using react 17.0.1 with yarn workspace. Because of this, it is crashing. I have to use 17 for the formic. I'm seeing the master branch already upgraded.

How can we solve this problem?

image

@ozanmanav
Copy link
Author

I guess it is not about the react version. It is creating another react folder with old version in the formik folder like this:

image
image

@johnrom
Copy link
Collaborator

johnrom commented Apr 29, 2021

You can add a property to your root workspace package.json:

"resolutions": {
  "react": "^17",
  "react-dom": "^17"
}

This will override the react package resolved for all workspace projects and their respective packages.

If you're using react native you may need to add that instead of Dom, or you might not need either.

@jaredpalmer
Copy link
Owner

@johnrom is this is as easy as just cutting a new release?

@johnrom
Copy link
Collaborator

johnrom commented May 12, 2021

(revised as I realized yarn --peer exists)

(revised again as I realized --peer only exists for yarn add --peer)

Hmm.. yes and no? I don't really know why the user is receiving this issue -- Yarn doesn't pull dev dependencies into the users node modules. I assume the user used yarn add --peer formik which installed peer deps automatically. I'm not sure if adding the peerDependencies versions listed below would resolve correctly automatically using yarn add --peer.

@ozanmanav Are you using link to connect a physically downloaded / cloned version of Formik to your workspace? If you are simply using Formik as a dependency via package.json:dependencies, it will not (or shouldn't) download React for you at all, as it is a peer dependency.

If you used yarn add --peer when you installed Formik, I suggest simply removing the second version of React (16.8.x) added to your subrepo.

If we want to update peer dependencies (we should), the format is a little different. I messed around with it in one of my old PRs but it isn't any of the ones I currently have open and I couldn't find it. The format is something like this:

"peerDependencies": {
  "react": ">=17 || >=16.8.0"
}

I don't think I ever got yarn workspaces to stop complaining about React when using this technique. I just wrote that out by hand so it might not be exactly that, and I'm not sure it actually works. YMMV. These versions include any React version which supports hooks.

Yarn mentions the Union operator in the docs here: https://classic.yarnpkg.com/en/docs/dependency-versions/#toc-unions

I tried the following values:

{
  "react": ">=16.8.0 <18", // between 16.8 and 17.x
  "react": "^17 || ^16.8.0", // I like this version better
  "react": ">=17 || >=16.8.0", // this version looks weird
}

Looks like its fixed in Yarn@2.x

@github-actions
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants