Build failling because of deprecated --frozen-lockfile flag on yarn install

I have a Rails 7 app with esbuild and yarn. The build is failing on the command yarn install --frozen-lockfile with the following output:

=> ERROR [build 6/9] RUN yarn install --frozen-lockfile                                                                                                               0.9s
------
 > [build 6/9] RUN yarn install --frozen-lockfile:
#0 0.736 ➤ YN0050: The --frozen-lockfile option is deprecated; use --immutable and/or --immutable-cache instead
#0 0.736
#0 0.788 ➤ YN0000: · Yarn 4.0.1
#0 0.802 ➤ YN0000: ┌ Resolution step
#0 0.864 ➤ YN0000: └ Completed
#0 0.887 ➤ YN0000: ┌ Post-resolution validation
#0 0.887 ➤ YN0028: │ The lockfile would have been modified by this install, which is explicitly forbidden.
#0 0.887 ➤ YN0000: └ Completed
#0 0.888 ➤ YN0000: · Failed with errors in 0s 99ms

How can I solve this and correctly build my app either by fixing something on my app configuration or some config on the fly builder?

There is two problems going on here. One is that frozen-lockfile was replaced with immutable starting in yarn 2, but apparently was just an alias and now starting with yarn 4 produces a warning. But that is just a warning.

You can change the Dockerfile to get rid of this warning, but the error will remain. I’ve opened an issue for this: replace frozen-lockfile with immutable for yarn >= 2 · Issue #65 · fly-apps/dockerfile-rails · GitHub

The more important question: why is your yarn.lock “stale”? There normally are two reasons for this. One is simply that you haven’t run “yarn install” on your machine since the last change to the dependencies in your package.json. The other is that you have installed native gems for your platform (perhaps M1/M2 or arm?), but these won’t work on the target machine. This can be corrected with:

bundle platform --add-platform=x86_64-linux
2 Likes

Thank you for your reply! You were correct, the yarn warning wasn’t the problem, but a stale lockfile. Weirdly though, it seems it was because of the package.lock instead of the yarn.lock, because I am sure I had run yarn install after the last changes, and my issue was solved by running npm install instead, the deploy finished fine after that. Based on your tip of the lockfile being stale, the issue was solved by running npm install. Removing the package-lock.json file resulted in this error:

=> ERROR [build 5/9] COPY --link package.json package-lock.json yarn.lock ./                                                                                          0.0s
------
 > [build 5/9] COPY --link package.json package-lock.json yarn.lock ./:
------
Error: failed to fetch an image or build from source: error building: failed to solve: failed to compute cache key: "/package-lock.json" not found: not found