Adam C. |

Have you ever encountered the cryptic ERR_PNPM_FROZEN_LOCKFILE_WITH_OUTDATED_LOCKFILE error while trying to run pnpm install --frozen-lockfile? If you're using pnpm as your package manager, this error might have left you scratching your head. In this blog post, we'll dissect this error message and guide you through the process of resolving it.

Photo by Rahul Mishra on Unsplash

Understanding the Error

The error message itself provides some valuable clues. It essentially tells you that you cannot perform a frozen installation because the version of the lockfile is incompatible with the current version of pnpm. This means that the lockfile, which is generated during the initial installation of your project's dependencies, was created with a different version of pnpm.

Checking pnpm Versions

Your first step in troubleshooting this issue was to compare the pnpm versions on your local machine and the AWS server. For example,  on your local machine, you found that you were running pnpm version 7.29.1, but on the AWS server, it was version 8.8.0. This version discrepancy could potentially be the root cause of the problem.

Why No Error on the AWS Server Before?

You might be wondering why this version mismatch didn't throw an error on the AWS server initially. The possible reason lies in how pnpm handles lockfiles. When you create a project with pnpm, it generates a lockfile (pnpm-lock.yaml) that is designed to be compatible with different versions of pnpm. This flexibility allows you to use different pnpm versions without requiring constant lockfile updates.

So, even though your pnpm-lock.yaml was initially created with pnpm version 7 on your local machine, it was still compatible with pnpm version 8 on the AWS server. However, this compatibility is not maintained when you delete the pnpm-lock.yaml and create a new one.


Resolving the Issue

To resolve the version mismatch and fix the ERR_PNPM_FROZEN_LOCKFILE_WITH_OUTDATED_LOCKFILE error, you need to ensure that your local and server pnpm versions are aligned. Here's a step-by-step guide:

1. Check Where pnpm Is Installed

If you tried to upgrade pnpm using npm update pnpm -g but encountered issues. This might be because pnpm was installed by other method, for example via Homebrew on your local machine. Check where pnpm is installed:

$ which pnpm

If it points to a Homebrew installation, you'll need to uninstall it first.

2. Uninstall pnpm (Homebrew)

Of course, you can update pnpm via Brew, but if you want to maintain it via NPM, then you can uninstall

$ brew uninstall pnpm

3. Install/Update pnpm Globally

Install or update pnpm globally using npm:

$ npm install pnpm -g

This will ensure that both your local and server environments are using the same version of pnpm.

4. Delete node_modules and pnpm-lock.yaml

In your project directory, delete the node_modules directory and the pnpm-lock.yaml file:

$ rm -rf node_modules 
$ rm pnpm-lock.yaml

5. Reinstall Dependencies

Now, reinstall your project's dependencies using the updated version of pnpm:

$ pnpm install

This will generate a new pnpm-lock.yaml file with the correct pnpm version, ensuring compatibility between your local and server environments.

6. Deploy to AWS

Once you've completed these steps, deploy your updated project to AWS, and you should no longer encounter the ERR_PNPM_FROZEN_LOCKFILE_WITH_OUTDATED_LOCKFILE error.

In conclusion, resolving the ERR_PNPM_FROZEN_LOCKFILE_WITH_OUTDATED_LOCKFILE error involves aligning the pnpm versions on your local machine and your server, and ensuring that the pnpm-lock.yaml file is generated with the correct version. By following these steps, you can ensure smooth and error-free deployments of your Node.js projects using pnpm. Happy coding!