yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.4k stars 2.73k forks source link

yarn workspace don't resolve exactly version package #8606

Open nvthuong1996 opened 3 years ago

nvthuong1996 commented 3 years ago
yarn --version
1.22.10

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

Dependency:

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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 commented 1 year ago

any progress? faced the same problem as described above