Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yarn install package from npm and not workspace

I'm encountering a problem with yarn workspaces, here is my situation :

I have a monorepo that contains :

  • a packages folder containing npm packages
  • an apps folder containing nodejs apps

In one of my apps, I'm trying to install a package from my packages folder that is published in npm, but when I do yarn install, it keeps using the workspace folder and doesn't download the npm package nor updates the yarn lock.

How can I tell yarn to not use the workspace folder for install but download it from the remote? I'm using the workspaces only for local builds.

like image 714
user3574857 Avatar asked Sep 03 '25 14:09

user3574857


1 Answers

If you are using yarn berry, it looks up the package in your workspace first and remote registry after. This behavior can be changed by setting enableTransparentWorkspaces: false in your .yarnrc.yml file at root.

// .yarnrc.yml

enableTransparentWorkspaces: false
...

If you want to get a package from your workspace with the above option is set, you should explicitly add workspace: protocol as a prefix for your package name in your package.json.

"my-package": "workspace:^2.0.17",

See more at:

  • https://yarnpkg.com/configuration/yarnrc#enableTransparentWorkspaces
  • https://yarnpkg.com/features/protocols
like image 129
JunKim Avatar answered Sep 05 '25 15:09

JunKim