Search code examples
javascriptyarnpkg

Why does Yarn modify package version in peer dependencies?


I was trying out Yarn V2 and put one of the dependencies in one workspace into the peerDependency section. But Yarn always modifies the version of the dependency to * no matter what version I wrote. Like this:

package.json (before)

{ "peerDependencies": { "packageA": "workspace:^0.0.1" } }

package.json (after)

{ "peerDependencies": { "packageA": "*" } }

where packageA is another local workspace managed by the monorepo. Doesn't * mean any version would satisfy? If this is a known Yarn feature, how could I specify a version in peer dependencies?


Solution

  • If you need to use another workspace dependency into your current dependency, you need to specify it inside devDependencies section like this

    { "devDependencies": { "packageA": "workspace:^0.0.1" } }