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:

The same happens with:
pnpm add -g pnpm
Additional information:
node -vprints: v18.12.1- Windows, macOS, or Linux?: Windows 11 Pro
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 53
- Comments: 70 (3 by maintainers)
If anyone is still having issue with this problem, might I suggest running
pnpm.cmd add -g pnpm @pnpm/exeand see if that fixes things? (It did work for me, personally)Have you tried to run your terminal with admin permissions?
here is the solution i tested:
Does the standalone script work to reinstall pnpm?
https://pnpm.io/installation#on-windows
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:
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).If pnpm is installed as described in 1. you can not update pnpm with pnpm. If you execute
pnpm add - pnpmorpnpm add - @pnpm/exepnpm 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 runpnpm env use --global ltsand 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 examplepnpm env use --global ltsyou 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?
I think
pnpm add -g @pnpm/exeshould also be fixed. But use this upgrade method for now.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
solved the issue for me! thanks
The solution is very simple, just go to the official website to find the installation command and execute it.
Although there is a solution, it’s infuriating that the
pnpm self-updatecommand, which many people can’t use, is still being shown as an upgrade prompt. The developers are being quite irresponsible, and that’s what’s most frustrating.Deleting the C:\Users[YOUR_USER]\AppData\Local\pnpm directory worked for me
This worked for me. Just run it as Admin with cmd/Power shell both works. 😉 if cmd didn’t work. try the Power shell as administrator.
npm install -g --force pnpmSame here with Win11 and Node v16.15.0
I agree with you that I wrote a small command alias:
Write it to your
$profilefile.After saving the file, in a new terminal window, enter the command
pnpm-upand your pnpm will be automatically updatedIf this message has helped you, please like it so that more people can see it
@adelarsq This problem is caused by the existence of an old version of pnpm and installing
shat the time of execution. The execution of sh downloaded the newpnpm.exefile and moved it to the old working path. But when executing the pnpm setup command. Because the old pnpm still exists, thepnpm setupwas not executed correctly (log:No changes to the environment were made. Everything is already up to date.), but thepnpm.exefile was not removed after the execution failed, and the same directory An older version of the pnpm file exists under . When executingpnpm [command]next time, the pnpm.exe file will always be invoked instead of the correct pnpm executable. So that caused this errorThis 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.EXEand then clickingEnd taskI hope this helps.
@zkochan yes that worked. 🎉
Does that mean that we have to open powershell and run:
in order to upgrade pnpm?
Because even on the latest version, the issue still persists: (after upgrading to the latest version)
what is the progress on this issue?
@PMA365 How does this work? My pnpm.exe is in
/AppData/Local/pnpm/pnpm. Installing pnpm vianpminstallspnpminC:\Users\[username]\AppData\Roaming\npm.The only thing that worked for me was running the following in Powershell (admin), based on @abcfy2 comment.
I ran into this issue with an install via Powershell:
I deleted that install and installed via npm instead
And the repro went away.
iwr https://get.pnpm.io/install.ps1 -useb | iexuse this to update
Wait for a best practice 👀
This has worked for me! pnpm updated to the latest version.
Isn’t this the chicken and egg problem? Isn’t the pnpm.exe file running while trying to delete (unlink) itself?
this worked for me
Having the separate binary be JS does not work for pnpm-managed node, however. That runs afoul of node trying to overwrite itself, which Windows wouldn’t like. Consequently, a separate native-code binary might be best so that it doesn’t conflict with the open node or pnpm processes.
This sadly changed nothing. I used
pnpm add -g pnpmall 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
pnpmwith using powershell i.e.iwr https://get.pnpm.io/install.ps1 -useb | iex@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
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 executedpnpm -vagain it printed v8.3.1 After that it works fineYes and it didn’t change anything. Let me know if you need me to provide more details about my env or to do some more testing.
In your project: 2. Corepack enable(if not enabled) 3. Update package.json: { “name”: “my-project”, “version”: “1.0.0”, “packageManager”: “pnpm@10.0.0” }
You can update the version updating package.json
I simply downloaded the install script and modified it briefly, then renamed it pnpm-up and copied it to the $PNPM_HOME folder, then I could use pnpm-up instead of pnpm self-update
Like @huntermasonb,
That’s also the only thing that worked for me. Renaming
pnpm.exeto something else then runningpnpm 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 pnpmsuccessfully.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.
fixed this problem after running
pnpm store pruneSee: https://pnpm.io/cli/storeI believe due to admin rights restriction on my machine, I installed pnpm using
corepack enableand I faced the issue after upgrading node to v18 and attempting topnpm -g update pnpm. Not sure which one caused the issue, however, after installing node, I justcorepack enableagain then it worked.@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.