bun icon indicating copy to clipboard operation
bun copied to clipboard

`bun install` installs optional dependency with optional=false in bunfig.toml

Open Osmose opened this issue 1 year ago • 3 comments

What version of Bun is running?

1.0.13+d8ca6ca69

What platform is your computer?

Darwin 22.5.0 x86_64 i386

What steps can reproduce the bug?

Create a directory with two files:

package.json

{
  "name": "test",
  "dependencies": {
    "chokidar": "^3.5.3"
  }
}

bunfig.toml

[install]
optional = false

Then run bun install and ls node_modules/fsevents to check if fsevents (which is an optional dependency for chokidar) was installed.

What is the expected behavior?

node_modules/fsevents wasn't installed and doesn't exist.

What do you see instead?

fsevents is installed under node_modules/fsevents.

Additional information

Ran into this while attempting to make a standalone binary with bun build that uses chokidar—#3903 prevents this from working since fsevents is a native module, so I'd like to avoid installing it since it's an optional dependency to chokidar, but bun seems to install it regardless of my bunfig.toml, --production flags, etc.

I also checked that it wasn't a cache issue by running rm -rf ~/.bun/install/cache, it still installs fsevents.

Osmose avatar Nov 22 '23 22:11 Osmose

Having the same issue with a dependency that has typescript as a peerOptional dependency, but it's installed no matter what I try.

joakimbeng avatar Feb 08 '24 16:02 joakimbeng

Same on Linux. Thought I was losing my mind. And this is not just optional dependences, but none of the dependency types documented under https://bun.sh/docs/runtime/bunfig#package-manager follow those settings. I've tried setting dev and peer to false and are always installed.

Also documented here: https://bun.sh/docs/cli/install#configuration

EDIT: unless I'm misunderstanding how this is expected to work. I can now see that the settings apply to my own project dependencies, but NOT to transitive dependencies (where optional still installed)

infrahead avatar Feb 11 '24 21:02 infrahead

For some reason it seems to skip the optional dependencies correctly when I install dependencies as part of a docker build when I have the dependency's optional dependency as a dev dependency and only install production dependencies though.

This is my Dockerfile:

FROM oven/bun:1.0.26-alpine
ENV CI true
ENV NODE_ENV production

COPY package.json package.json
COPY bun.lockb bun.lockb

RUN bun install --production --frozen-lockfile

When I run a container with that built image the optional dependency is not installed, which is correct. I don't know if it's the NODE_ENV or CI env variables that affect it in some way to make it behave correctly...

joakimbeng avatar Feb 12 '24 08:02 joakimbeng

I am seeing this issue in Bun v1.1.3. I set [install.optional] = false in bunfig.toml, but sharp, an optional dependency of astro, is still installed, which is not expected.

Alecyrus avatar Apr 10 '24 04:04 Alecyrus

👍

jbsiddall avatar May 05 '24 18:05 jbsiddall

present in 1.1.17

dszymon avatar Jul 02 '24 13:07 dszymon