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

yarn workspace don't resolve exactly version package #8606

Open
nvthuong1996 opened this issue Mar 31, 2021 · 4 comments
Open

yarn workspace don't resolve exactly version package #8606

nvthuong1996 opened this issue Mar 31, 2021 · 4 comments

Comments

@nvthuong1996
Copy link

nvthuong1996 commented Mar 31, 2021

yarn --version
1.22.10

I has two package in mono project use yarn workspace
package1: landingpage
package2: webapp

Dependency:

  • landingpage depend react@17, antd@4
  • webapp depend react@16, antd@4
  • antd@4 has peerDependencies "react": ">=16.9.0"

I use nohoist

  "workspaces": {
    "packages": ["packages/*"],
    "nohoist": ["landingpage/**","webapp/**"]
  },

When i run yarn to install package
landingpage install react@17 but i found react@16 in ant package:

rootProject/packages/landingpage/node_modules/react version 17
rootProject/packages/landingpage/node_modules/antd/node_modules/react version 16

Landingpage use react@16 and react@17 => error

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

Please help me !!

@joeyfigaro
Copy link

joeyfigaro commented Mar 31, 2021

@nvthuong1996 have you tried adding resolutions to both of your package.json files?

// landingpage/package.json
{
  "name": "landingpage",
  // ...
  "resolutions": {
    "react": "17.0.0" // <- specific required version
  }
}

// webapp/package.json
{
  "name": "webapp",
  // ...
  "resolutions": {
    "react": "16.0.0" // <- specific required version
  }
}

@nvthuong1996
Copy link
Author

i allready try but it not working.
please try at https://github.com/nvthuong1996/test-yarn-workspace and compare react version

rootProject/packages/webapp/node_modules/antd/react
vs
rootProject/packages/webapp/node_modules/react


rootProject/packages/web/node_modules/antd/react
vs
rootProject/packages/web/node_modules/react

@zemse
Copy link

zemse commented Apr 2, 2021

I am facing a similar problem. I removed the ^ in the dependency version in package.json (from "^16.9.0" to "16.9.0") and that solved problem for me.

I had a yarn.lock inside each individual workspace, but no yarn.lock in the project root. It appears that yarn ignores the inside yarn.locks. In my usecase, I am creating a mono repo of existing repositories. I think yarn should also check the inside workspace yarn.lock files to install the correct version of the package and build the root yarn.lock according to that.

@akaSybe
Copy link

akaSybe commented Apr 7, 2023

any progress? faced the same problem as described above

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

No branches or pull requests

4 participants