bun
bun copied to clipboard
`bun add` or `bun install` ALWAYS hoists packages in workspace/monorepo
What version of Bun is running?
1.0.15+b3bdf22eb
What platform is your computer?
Darwin 23.0.0 arm64 arm
What steps can reproduce the bug?
- Create a bun monorepo
{
"name": "my-project",
"private": true,
"workspaces": [
"backend",
"frontend"
]
}
- In this example, I have a
frontend
andbackend
folder that hosts two apps. The backend is anexpress
app and the frontend is areact-native
app. - If I
cd backend
orcd frontend
into a directory and runbun add uuid
(uuid
is just an example package), it creates a"dependencies"
object in my rootpackage.json
which doesn't make sense. The package doesn't need to be hoisted if it is just being used in one package. This happens no matter which package I try installing.
What is the expected behavior?
The package is added to frontend/package.json
or backend/package.json
depending on what the cwd
is but not in the root package.json
What do you see instead?
The package is in the root package.json
like this:
{ "name": "my-project", "private": true, "workspaces": [ "backend", "frontend" ], "dependencies": { "uuid": "^9.0.0" } }
Additional information
No response
I'm getting a slightly different behaviour:
- When running "bun install a-package" it gets added to the root package.json even when run in one of the workspaces.
- When running "bun add a-package" it does get added to the expected (cwd) package.json. BUT then the lockfile gets messed up (seems to only contain dependencies of the (cwd) package.json after this - I need to run a new
bun install
to fix it). (Added a new issue #7844 for this since it could probably be considered a separate issue)
Note: I'm specifying my workspace slightly different:
"workspaces": [
"apps/*",
"packages/*"
],
I can replicate this issue in a mono-repo using bun install
. Any new packages added within a repo are hoisted to the root instead.
bun add
works correctly though in terms of the packages being added to the repo as @robertherber mentioned.
I have to add packages via bun add <pkg>
, which corrupts the lockfile. Then I have to run bun i
.
bun.lockb
file is missing in child repos.
I use this script for now:
{
"scripts": {
"predev": "bun i && cp ../../bun.lockb ."
}
}
Related solution here until bun supports monorepos fully, use it by installing @zemble/utils
and running bun add-safe <pkg-name>
or simply copying the script to your project :)
Related solution here until bun supports monorepos fully, use it by installing
@zemble/utils
and runningbun add-safe <pkg-name>
or simply copying the script to your project :)
Thank you for this @robertherber, we'll use this script for the time being.
Hoping @Jarred-Sumner has a native fix for this coming soon! 🤞🏼
I don't know if it is related, but I have a monorepo with some Next.js applications. Bun is hoisting the node_modules/.bin/next
directory, which causes a lot of errors when I want to build my project. In development mode, everything works. Copying the node_modules/.bin/next
from another project makes the build work.
I just wanted to also +1 this. We are using bun
at the moment through turbo
and honestly, getting a Docker container ready and using it dev wise has been the most painful experience ever.