pnpm: Can't upgrade pnpm version: EPERM: operation not permitted, unlink `AppData\Local\pnpm\pnpm.EXE`

pnpm version: 7.16.1

Code to reproduce the issue:

I have only installed pnpm in my Windows 11 laptop because I want to manage node.js versions with it. When I install dependencies in a project, I get an warning to upgrade pnpm to a newer version by running

pnpm add -g @pnpm/exe

Expected behavior:

Normally that command should work.

Actual behavior:

After running that command I get:

image

The same happens with:

pnpm add -g pnpm

Additional information:

  • node -v prints: v18.12.1
  • Windows, macOS, or Linux?: Windows 11 Pro

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 20
  • Comments: 34 (3 by maintainers)

Most upvoted comments

If anyone is still having issue with this problem, might I suggest running pnpm.cmd add -g pnpm @pnpm/exe and see if that fixes things? (It did work for me, personally)

Does the standalone script work to reinstall pnpm?

https://pnpm.io/installation#on-windows

I think pnpm add -g @pnpm/exe should also be fixed. But use this upgrade method for now.

If anyone is still having issue with this problem, might I suggest running pnpm.cmd add -g pnpm @pnpm/exe and see if that fixes things? (It did work for me, personally)

solved the issue for me! thanks

Some time has passed and pnpm has been updated to v8. Is there any progress on this issue?

I’m having the same problem on Windows 10.

@zkochan

Have you tried to run your terminal with admin permissions?

@adelarsq This problem is caused by the existence of an old version of pnpm and installing sh at the time of execution. The execution of sh downloaded the new pnpm.exe file and moved it to the old working path. But when executing the pnpm setup command. Because the old pnpm still exists, the pnpm setup was not executed correctly (log: No changes to the environment were made. Everything is already up to date.), but the pnpm.exe file was not removed after the execution failed, and the same directory An older version of the pnpm file exists under . When executing pnpm [command] next time, the pnpm.exe file will always be invoked instead of the correct pnpm executable. So that caused this error

Same here with Win11 and Node v16.15.0

I ran into this issue with an install via Powershell:

iwr https://get.pnpm.io/install.ps1 -useb | iex

I deleted that install and installed via npm instead

npm i -g pnpm

And the repro went away.

fixed this problem after running pnpm store prune See: https://pnpm.io/cli/store

This sadly changed nothing. I used pnpm add -g pnpm all the time to update my pnpm until recently. Now it suddenly stopped working, this is a bit annoying, to always update via PowerShell (Windows 10 btw)

I still have this error after installing pnpm with using powershell i.e. iwr https://get.pnpm.io/install.ps1 -useb | iex

$ pnpm --version
8.6.12

$ pnpm add -g pnpm
Nothing to stop. No server is running for the store at C:\Users\foobar\AppData\Local\pnpm\store\v3
Packages: +1
+
Progress: resolved 1, reused 1, downloaded 0, added 0, done
 WARN  The target bin directory already contains an exe called pnpm, so removing C:\Users\foobar\AppData\Local\pnpm\pnpm.EXE
 EPERM  EPERM: operation not permitted, unlink 'C:\Users\foobar\AppData\Local\pnpm\pnpm.EXE'

@thakyZ I don’t have pnpm.cmd, just npm.cmd, is that what you meant?

Either way, I’ve switched to using winget to manage pnpm versions and so far it’s worked flawlessly.

I ran into the same problem. After I encountered a strange problem I reinstalled pnpm using the following command

iwr https://get.pnpm.io/install.ps1 -useb | iex

Then I installed the latest pnpm@8.6.10

But when I use it, this problem occurs. When I execute pnpm i -g. I find that it reinstalls the pnpm@8.3.1 that I used before I felt strange, so when I directly renamed pnpm.exe to another name, when I executed pnpm -v again it printed v8.3.1 After that it works fine

TL;DR: On Windows an executable which is executed can not be removed. Depending on how pnpm was installed this breaks either the self update or the env command to change the Node version. So a solution needs to be implemented possibly involving renaming the current running executable.

I investigated this issue a little bit, because i wanted to use pnpm on Windows to manage my Node Version. There are at least two ways pnpm can be installed on windows:

  1. If you use the Installation Instructions on the Website (iwr https://get.pnpm.io/install.ps1 -useb | iex) you are left with a single binary in the users AppData directory (C:\Users***\AppData\Local\pnpm\pnpm.exe).
  2. If you install pnpm with the help of another Package Manager you are left with pnpm installed in a node_modules folder and the common pnpm shell files (pnpm, pnpm.cmd, pnpm.ps1) which will call the node.exe binary with pnpm in these shell folders.

If pnpm is installed as described in 1. you can not update pnpm with pnpm. If you execute pnpm add - pnpm or pnpm add - @pnpm/exe pnpm will try to delete the pnpm executable which is currently executed (pnpm is running right now). With this installation of pnpm it is possible to manage the node version. You can run pnpm env use --global lts and pnpm will download and install node and npm in to the AppData directory. Also pnpm has no problem unlinking the node.exe file because pnpm is run with the pnpm.exe binary.

If pnpm is installed as described with 2. you can update pnpm by running pnpm add - pnpm. Because now the update does not involve deleting the current running Binary (node.exe). pnpm only changes the files in the node_modules folder. In Windows point of view these files are normal text files which also have been read (but not locked) by node.exe. So they can be overridden. If you try to change the node version with for example pnpm env use --global lts you will get the an error for the same reason pnpm could not update itself in the first case. Now again pnpm trys to delete (unlink) the file which is currently running (node.exe).

My proposal for a solution would be to create a special case for the node.exe and pnpm.exe files. If the delete/unlink fails on these files, rename them to something like pnpm.exe.del instead. If for some reason that file already exists use pnpm.exe.2.del or pnpm.exe.3.del and so on. On subsequent runs of pnpm we could check for files with this naming scheme inside of the AppData directory and delete them. This can be a special case, which is only used on windows.

I would like to hear feedback on this idea. Is there a better way to solve this chicken and egg problem?

Like @huntermasonb,

That’s also the only thing that worked for me. Renaming pnpm.exe to something else then running pnpm add -g pnpm, it is indeed a permission issue.

After the update to 8.12 I ran into this issue. I was getting "operation not permitted, unlink ‘C:***\Local\pnpm\pnpm.EXE’ ". I was able to work around this by renaming the 8.11 pnpm.exe file to “old-pnpm.exe”, then ran pnpm add -g pnpm successfully.

I deleted the old .exe file and it seems to be fine for now, but I haven’t restarted my PC yet so I’ll find out once I do.

@amihhs That is a permission problem. Files on Windows are locked on use. So that explains why renaming pnpm.exe for another name works. But why its been blocked doesn’t make sense.

This is a common issue on windows in my experience, with a number of different services, though for me its normally esbuild.

I would suggest hitting Ctrl + Shift + Esc and finding the running process, in this case its likely pnpm.EXE and then clicking End task

I hope this helps.