How to run `bun install` in a different directory than the current?

406 views Asked by At

For instance, say I'm in the parent folder of app folder where package.json is, and I want to install dependencies for app without cd into it.

I tried:

bun --prefix app install # the npm way
bun --dir app install # the pnpm way
bun --cwd app install # the bun way, but only works with `run` scripts like `bun start`

None of the above worked. Is it supported at all?

1

There are 1 answers

0
Edoardo Scibona On

If the directory structure is parent > app > package.json and you are currently in parent, you can install all dependencies with this command:

bun install --cwd ./app

If you need to install a new dependency, for example react, you can use this command:

bun add react --cwd ./app

This command will also create a package.json file if not present.