ā ļø Do you encounter this error? Scroll down for the solution
$ npm i typescript -g
npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path C:\Program Files\nodejs\node_modules\.typescript-sYNOr6Zf
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_modules\.typescript-sYNOr6Zf'
npm ERR! [Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_modules\.typescript-sYNOr6Zf'] {
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'mkdir',
npm ERR! path: 'C:\\Program Files\\nodejs\\node_modules\\.typescript-sYNOr6Zf'
npm ERR! }
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\User\AppData\Local\npm-cache\_logs\2021-06-10T07_30_08_762Z-debug.log
Unexpected warning for http://registry.npmjs.org/: Miscellaneous Warning EINTEGRITY: sha512-P7LsZabTIMUxH8wXtAwQ/7xbtbx8kK3Xt+a6JO2bAsjLnJWQib4UK+ywMRt1aN4p1wBxG5Yu7qrZQ0nsjXP6LA== integrity checksum failed when using sha512: wanted sha512-P7LsZabTIMUxH8wXtAwQ/7xbtbx8kK3Xt+a6JO2bAsjLnJWQib4UK+ywMRt1aN4p1wBxG5Yu7qrZQ0nsjXP6LA== but got sha512-iYmAdAwGW898xFeo8XtnXTOpkXzMjWUcDvdoWAoHYHh5c0513XmNIP2Xx7yyQ1Jpofb5iwShOpUrzOKFrnNqZQ==. (4143281 byteglemaps npm package, which iss)
npm WARN registry Using stale data from https://registry.npmjs.org/ due to a request error during revalidation.
npm ERR! code FETCH_ERROR
npm ERR! errno FETCH_ERROR
npm ERR! invalid json response body at https://registry.npmjs.org/@ionic%2fcore reason: Unexpected token in JSON at position 16
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\User\AppData\Local\npm-cache\_logs\2021-06-11T09_14_36_233Z-debug.log
[ERROR] An error occurred while running subprocess npm.
Solution
I tried to disabled all my antivirus and firewall, clear npm cache, and do cache verify but nothing works. The only thing that works on my end is to install the Node Version Manager nvm.
How Node Version Manager works?
Permission errors can occur when packages are installed globally. If this is the case, npm may need to be set up to operate without elevated permissions. This where nvm comes in. It lets you install a different node version without triggering the administrative access.
- If you have existing Node installed, I recommend uninstalling it like the process given by LOTUSMS above
Uninstall from Programs & Features with the uninstaller.
Reboot (or you probably can get away with killing all node-related processes from Task Manager).
Look for these folders and remove them (and their contents) if any still exist. Depending on the version you installed, UAC settings, and CPU architecture, these may or may not exist:
C:\Program Files (x86)\Nodejs C:\Program Files\Nodejs
C:\Users{User}\AppData\Roaming\npm (or %appdata%\npm)
C:\Users{User}\AppData\Roaming\npm-cache (or %appdata%\npm-cache)
C:\Users{User}.npmrc (and possibly check for that without the . prefix too) Check your %PATH% environment variable to ensure no references to Nodejs or npm exist.
If it's still not uninstalled, type where node at the command prompt and you'll see where it resides -- delete that (and probably the parent directory) too.
Install nvm here - https://github.com/coreybutler/nvm-windows. or you can use curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
Run
nvm
orcommand -v nvm
. If something prints, the installation was successful.Install prefered node version - e.g. nvm use 16.3.0
Check if the node and npm are properly install. Just run
node -v
andnpm -v
Enjoy npm installation š