Search code examples
pnpm

How do I avoid lock file conflicts with PNPM?


Our team uses PNPM and a recurring problem is that we seem to have different versions of the pnpm command installed, causing lock files git conflicts when adding or updating packages. PNPM is a global tool, so I am not totally sure how to handle this situation. Some Node tools have a global CLI interface (Grunt), but utilize a locally installed package to avoid this issue. Does PNPM have a way to ensure consistent behavior across the team to avoid lock file conflicts and such?


Solution

  • The current recommended approach is to declare which pnpm version should be used in the project. It may be done via the engines field of packages.json. For instance, if your project should be used with pnpm v6, add this to package.json:

    {
        "engines": {
            "pnpm": "6"
        }
    }
    

    If someone will run pnpm install using a different version of pnpm, an error will be thrown.

    In the future we might automatically download the right version of pnpm and use it. Kind of how Yarn does it with version policies.