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 -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)
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.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 newpnpm.exe
file and moved it to the old working path. But when executing the pnpm setup command. Because the old pnpm still exists, thepnpm setup
was not executed correctly (log:No changes to the environment were made. Everything is already up to date.
), but thepnpm.exe
file 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 errorSame here with Win11 and Node v16.15.0
I ran into this issue with an install via Powershell:
I deleted that install and installed via npm instead
And the repro went away.
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
@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 -v
again it printed v8.3.1 After that it works fineTL;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 - pnpm
orpnpm 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 runpnpm 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 examplepnpm 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 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 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 clickingEnd task
I hope this helps.