Easy Solution to ERR_PNPM_ADDING_TO_ROOT Error

Posted January 18, 2024
Easy Solution to ERR_PNPM_ADDING_TO_ROOT Error

This simple Guide shows how to solve the ERR_PNPM_ADDING_TO_ROOT Error that occurs when using pnpm in your Projects

What Causes ERR_PNPM_ADDING_TO_ROOT Error

If you are using the pnpm commands such as pnpm install, pnpm add, and pnpm init, Just to name a few ERR_PNPM_ADDING_TO_ROOT Error will occur due to:

  • PNPM version incompatibility
  • Your PNPM cache is corrupted or outdated
  • You have dependency conflicts in your package.json file
  • Any pnpmfile misconfigurations will affect the installation process.

These a few cases of ERR_PNPM_ADDING_TO_ROOT

The Challenge with ERR_PNPM_ADDING_TO_ROOT Error

I have one issue here. ERR_PNPM_ADDING_TO_ROOT error has different root causes. This makes it extremely hard to figure out exactly what the problem is.

The confusing part is, that this error will be seen in some frameworks such as Remix and Next.js. But you will be confused to find out other frameworks working fine even with the same PNPM setup.

Or your project works locally but not on other environments such as Vercel:

Easy Solution to ERR_PNPM_ADDING_TO_ROOT Error

Image Source

Let’s consider using vite to ERR_PNPM_ADDING_TO_ROOT Error

Solution One: If using Vite and PNPM Monorepo

Let’s say you are using Vite on your project and across different PNPM packages.

To share vite dependency on your packages, you need to install vite on the root directory using the command:

pnpm add vite

But this will pop up the ERR_PNPM_ADDING_TO_ROOT Error. So the same ERR_PNPM_ADDING_TO_ROOT error is being reported when running a PNPM installation command:

Easy Solution to ERR_PNPM_ADDING_TO_ROOT Error

If you are using Vite with pnpm monorepo workspace, install dependencies globally to the root directory with --workspace-root (-w) as follows:

pnpm add vite -w

Solution Two: The Purpose of ERR_PNPM_ADDING_TO_ROOT

This error pops up on commands trying to install dependencies on the root PNPM workspace. Now, might not want to do so. Always use the w flag.

If this fails, try clearing the cache:

pnpm cache clear

If you don’t want this warning on your terminal ignore it with the command:

pnpm config set ignore-workspace-roor-check true

Conclusion

This could be the reason you are having an ERR_PNPM_ADDING_TO_ROOT error. However, this post doesn’t guarantee all solutions related to this error. I solved ERR_PNPM_ADDING_TO_ROOT based on what I saw working with my problem.

Related: Solving ERR_PNPM_NO_MATCHING_VERSION_INSIDE_WORKSPACE Error

Easy Solution to ERR_PNPM_ADDING_TO_ROOT Error

Written By:

Joseph Chege