“npm install -g npm@latest” corrupted my npm installation - Windows 8.1 machine

Hello,
Last month I installed node 10.16.3 LTS and because it didn’t have latest npm version I’ve updated it using this official guide: https://docs.npmjs.com/try-the-latest-stable-version-of-npm (option 2):

  1. removed both %ProgramFiles%\nodejs\npm and %ProgramFiles%\nodejs\npm.cmd
  2. moved ‘npmrc’ file from %ProgramFiles%\nodejs\node_modules\npm to %appdata%\npm\node_modules\npm

Today, after I’ve installed ‘create-react-app’, npm showed me message that new minor version of npm is available 6.11.3 -> 6.12.0 and that I can update it.
I ran npm install -g npm@latest but that just threw me bunch of errors:

C:\Users\Wladyslaw\AppData\Roaming\npm\npx -> C:\Users\Wladyslaw\AppData\Roaming\npm\node_modules\npm\bin\npx-cli.js
npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path C:\Users\Wladyslaw\AppData\Roaming\npm\npm
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, open 'C:\Users\Wladyslaw\AppData\Roaming\npm\npm'
npm ERR!  { [Error: EPERM: operation not permitted, open 'C:\Users\Wladyslaw\AppData\Roaming\npm\npm']
npm ERR!   cause:
npm ERR!    { Error: EPERM: operation not permitted, open 'C:\Users\Wladyslaw\AppData\Roaming\npm\npm'
npm ERR!      errno: -4048,
npm ERR!      code: 'EPERM',
npm ERR!      syscall: 'open',
npm ERR!      path: 'C:\\Users\\Wladyslaw\\AppData\\Roaming\\npm\\npm' },
npm ERR!   stack:
npm ERR!    'Error: EPERM: operation not permitted, open \'C:\\Users\\Wladyslaw\\AppData\\Roaming\\npm\\npm\'',
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'open',
npm ERR!   path: 'C:\\Users\\Wladyslaw\\AppData\\Roaming\\npm\\npm' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Wladyslaw\AppData\Roaming\npm-cache\_logs\2019-10-17T19_35_58_442Z-debug.log

Now I can’t even run npm -v, it somehow removed my npm folder and just showing me this message:

bash: /c/Users/Wladyslaw/AppData/Roaming/npm/npm: No such file or directory

Is there any way to repair such damaged npm installation without reinstalling whole Node.js?
Thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.