Search code examples
herokuyarnpkgheroku-ci

getting YN0028 The lockfile would have been modified by this install, which is explicitly forbidden. using yarn berry and heroku


I'm using yarn berry and heroku and consistently getting the error:

       ➤ YN0028: │ The lockfile would have been modified by this install, which is explicitly forbidden.

Which suggests that my lockfile does not contain all my listed dependencies. In the yarn docs it says this is easily solved by running yarn install and pushing new lockfile to git. However I've tried this, tried with fresh node_modules, etc with no luck.

Has anyone else experienced this issue using yarn berry + heroku?

My repo is a monorepo using workspaces.


Solution

  • How to silence the error. ⚠ You don't want this!

    I was able to workaround by setting the env-var YARN_ENABLE_IMMUTABLE_INSTALLS to false, as suggested here.

    This is likely a bug in Yarn Berry. I've reported it here: https://github.com/yarnpkg/berry/issues/2948


    UPD: I have created a fresh local clone of the repo from GitHub, ran yarn install in it, and it did produce changes in yarn.lock. Committing those changes resolved the CI issue, so disabling YARN_ENABLE_IMMUTABLE_INSTALLS is no longer necessary for me.

    The original local repo showed a clean git status, so I still believe it is a bug.

    UPD 2: My problem was that one of the Yarn worspaces was checked into git as a git submodule (I have probably created it with a nested .git/ folder and then deleted it). As a result, the workspace content, including a child package.json was not committed into the repo, it only existed in my local repo and not on the remote and CI.

    After removing the git submodule and checking the workspace into the repo properly, the YN0028 error stopped happening.