Linking in monorepo creates unwanted original copy in packages/apps #26513
Replies: 3 comments
Solution: Bun Link in MonorepoThe issue is that Bun hoists the linked package to root but still resolves the catalog version for nested workspaces. Fix 1: Link in the specific workspacecd apps/my-app
bun link my-packageFix 2: Use workspace protocol instead of catalog// apps/my-app/package.json
{
"dependencies": {
"my-package": "workspace:*"
}
}Then link your local development version: cd packages/my-package
bun link
cd ../../apps/my-app
bun link my-packageFix 3: Override resolution in root package.json{
"overrides": {
"my-package": "link:./path/to/local/my-package"
}
}Then run Fix 4: Delete nested node_modules and reinstallrm -rf apps/my-app/node_modules
bun link my-package
bun installWhy this happensBun catalog resolution happens before link resolution. The workspace still tries to resolve from catalog, creating the nested copy. Using workspace protocol or overrides bypasses catalog lookup. |
|
The root of it: So when Given that, the fix is to make the package you're actively developing use // apps/my-app/package.json
{
"dependencies": {
"my-package": "workspace:*"
}
}Then |
|
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
If I run at the root:
bun link my-packageIt correctly replaces the
my-packagein the root.However it also then adds the original
my-packagecopies to the packages/apps:After running
bun link my-packageat the root:So when I start
my-appit still loads the unlinked package.How can I stop that from happening?
All reactions