oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.84k stars 2.56k forks source link

`bun install --frozen-lockfile` in workspaces works locally but fails when building docker image #12252

Open cybercoder-naj opened 1 week ago

cybercoder-naj commented 1 week ago

What version of Bun is running?

1.1.13+bd6a60512

What platform is your computer?

Linux 6.6.32-1-lts x86_64 unknown

What steps can reproduce the bug?

  1. Initialise a bun repo bun init
  2. Delete node_modules, bun.lockb and index.ts.
  3. Add "workspaces": ["server"] in package.json.
  4. Create an example server, I used bun create hono server. a. In the installation process, do not install dependencies.
  5. In the root directory of the monorepo setup, run bun install.
  6. Create a Dockerfile of the following:
FROM oven/bun:1.1.13
WORKDIR /app
COPY package.json bun.lockb server/package.json ./
RUN bun install --frozen-lockfile
COPY . .
CMD ["bun", "run", "dev"]

What is the expected behavior?

When I delete node_modules from the root directory of the project, bun install --frozen-lockfile succeeds without any error. However, when I build the docker image, the resultant error is,

bun install v1.1.13 (bd6a6051)
Resolving dependencies
Resolved, downloaded and extracted [2]
error: lockfile had changes, but lockfile is frozen
note: try re-running without --frozen-lockfile and commit the updated lockfile

What do you see instead?

Running it locally: image

But when building a docker image: 2024-06-29_22-07

Additional information

When building a docker image in a single project, it works. The issue is with bun workspaces.

Jarred-Sumner commented 1 week ago

Does this reproduce on Bun v1.1.17? The bun.lockb file is checked in to version control and copied to the Docker image right?

cybercoder-naj commented 1 week ago

Yes, in my monorepo setup, updating bun to 1.1.17 locally and changing the version of the docker image does not fix the issue. Also yes. I generate a new bun.lockb which is copied over to the docker image during build and errors when trying to build the docker image.

cybercoder-naj commented 6 days ago

Any resolutions to this thread?

bjon commented 3 days ago

@cybercoder-naj I had to copy my "packages" as well.

COPY packages packages

ps. I guess it fails cause without them, bun doesn't find any packages, in the workspace.

cybercoder-naj commented 3 days ago

Unfortunately, that did not solve the issue.. Inside of a docker environment, bun complains about the lock file being modified.

bjon commented 2 days ago

Hmmm strange. It works for me in Bun 1.1.18

bjon commented 2 days ago

And I got this in my package.json.

{
  "workspaces": ["packages/*"]
}
cybercoder-naj commented 10 hours ago

Here is my reproduction repo. Can you clone this and type two commands?

# First one
bun install --production

# Second one
docker build . --tag bun-issue:1.0.0

Is this an issue only on my system? Doesn't that defeat the entire purpose of docker?

cybercoder-naj commented 9 hours ago

Hmmm strange. It works for me in Bun 1.1.18

@bjon same issue with 1.1.18 :(