Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Rolanddoda opened this issue Nov 26, 2022 · 34 comments

Comments

@Rolanddoda
Copy link

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
@florian-lefebvre
Copy link

Same here with Win11 and Node v16.15.0

@zkochan
Copy link
Member

zkochan commented Nov 28, 2022

Have you tried to run your terminal with admin permissions?

@florian-lefebvre
Copy link

Yes 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.

@Rolanddoda
Copy link
Author

Have you tried to run your terminal with admin permissions?

Yes I did that, same error.

@zguiyang
Copy link

I have the same problem. Is there any temporary solution?

@zkochan
Copy link
Member

zkochan commented Nov 30, 2022

Does the standalone script work to reinstall pnpm?

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

@Rolanddoda
Copy link
Author

Rolanddoda commented Nov 30, 2022

@zkochan yes that worked. 🎉

Does that mean that we have to open powershell and run:

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

in order to upgrade pnpm?

Because even on the latest version, the issue still persists:
(after upgrading to the latest version)

image

@zkochan
Copy link
Member

zkochan commented Nov 30, 2022

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

@Rolanddoda
Copy link
Author

@zkochan please see my updated comment above! I updated it while you were adding the comment above

@ArcherGu
Copy link

Same problem 😢

@Deebster
Copy link

This issue also broke updating other packages:

PowerShell 7.3.1
PS C:\Users\micro> pnpm add -g wrangler
 WARN  deprecated rollup-plugin-inject@3.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
 WARN  deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
Packages: +462
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 485, reused 461, downloaded 0, added 0, done
 WARN  The target bin directory already contains an exe called pnpm, so removing C:\Users\micro\AppData\Local\pnpm\pnpm.EXE
 EPERM  EPERM: operation not permitted, unlink 'C:\Users\micro\AppData\Local\pnpm\pnpm.EXE'


PS C:\Users\micro> pnpm -v
7.25.0

In the end I had to delete all C:\Users\micro\AppData\Local\pnpm* directories and reinstall from there.

@Deebster
Copy link

Deebster commented Feb 7, 2023

This issue still exists in 7.25.1 (Win 10 Home 21H2):

PS C:\Users\micro> pnpm add -g @pnpm/exe

   ╭──────────────────────────────────────────────────────────────────╮
   │                                                                  │
   │                Update available! 7.25.1 → 7.26.3.                │
   │   Changelog: https://github.com/pnpm/pnpm/releases/tag/v7.26.3   │
   │         Run a script from: https://pnpm.io/installation          │
   │                                                                  │
   │      Follow @pnpmjs for updates: https://twitter.com/pnpmjs      │
   │                                                                  │
   ╰──────────────────────────────────────────────────────────────────╯

 WARN  deprecated rollup-plugin-inject@3.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
 WARN  deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
Packages: +2
++
Downloading registry.npmjs.org/@pnpm/win-x64/7.26.3: 17.4 MB/17.4 MB, done
Progress: resolved 496, reused 470, downloaded 2, added 2, done
.pnpm/@pnpm+exe@7.26.3/node_modules/@pnpm/exe: Running preinstall script, done in 299ms
 WARN  The target bin directory already contains an exe called pnpm, so removing C:\Users\micro\AppData\Local\pnpm\pnpm.EXE
 EPERM  EPERM: operation not permitted, unlink 'C:\Users\micro\AppData\Local\pnpm\pnpm.EXE'

@zhshch2002
Copy link

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

@ghost
Copy link

ghost commented Jul 3, 2023

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.

@Deebster
Copy link

Deebster commented Jul 5, 2023

@luke-hagar-sp but if you're using pnpm to update itself with the suggested command pnpm add -g @pnpm/exe, then pnpm.exe is always running.

This used to work, whereas now it seems to always (or usually?) fail with an EPERM error.

@amihhs
Copy link

amihhs commented Jul 25, 2023

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

@adelarsq
Copy link

@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.

@amihhs
Copy link

amihhs commented Jul 28, 2023

@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

@thakyZ
Copy link

thakyZ commented Aug 3, 2023

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)

@Deebster
Copy link

Deebster commented Aug 4, 2023

@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.

@thakyZ
Copy link

thakyZ commented Aug 5, 2023

@Deebster I had the path to PNPM_HOME on my path so that I could use the pnpm.cmd from where ever PNPM_HOME is at. I don't think there should be a npm.cmd in that folder, but I assume the PNPM_HOME was not added to your path, and if that wasn't the cause I am not sure what I have different.

I installed pnpm thought npm and then just ran into the issue recently. I was just leaving it as a fix if it may be an alternative fix for anyone else, since I didn't see it covered or mentioned.

@ibqn
Copy link

ibqn commented Aug 20, 2023

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'

@andrekat
Copy link

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

@mo9a7i
Copy link

mo9a7i commented Oct 8, 2023

I believe due to admin rights restriction on my machine, I installed pnpm using corepack enable and I faced the issue after upgrading node to v18 and attempting to pnpm -g update pnpm. Not sure which one caused the issue, however, after installing node, I just corepack enable again then it worked.

@Elvincth
Copy link

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

@kirbby
Copy link

kirbby commented Nov 2, 2023

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)

@itpropro
Copy link

Still no update?

@deeprobin
Copy link

I can repro

@huntermasonb
Copy link

huntermasonb commented Dec 12, 2023

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.

@MaxWilson
Copy link

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.

@Philboisvert
Copy link

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.

@IIIMADDINIII
Copy link

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?

@cwadrupldijjit
Copy link

cwadrupldijjit commented Mar 21, 2024

Perhaps having a separate executable that is called by pnpm.exe as the final step that is fed the location of the new pnpm binary and watches for the current pnpm process to be terminated; at that point, the pnpm.exe binary is not locked by Windows running it and should be able to be deleted.

Alternatively, the pnpm.exe binary could detect when pnpm is supposed to update and then invoke the JS version of the binary to update pnpm.exe. This requires, however, that the JS is installed and executed separately from the pnpm.exe binary. At the same time, using that alternative executable (in this case in JS) could be used to unlink/delete/replace the pnpm.exe binary.

@cwadrupldijjit
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests