'npm ERR! Error: EACCES: permission denied

I'm having this famous issue while trying to install Typescript in my react app. Concretely, I am running this: npm install --save typescript @types/node @types/react @types/react-dom @types/jest

and I am getting this response:

npm ERR! code EACCES npm ERR! syscall rename npm ERR! path /mnt/c/Users/asier/dev/nftgram/web/node_modules/@types/node npm ERR! dest /mnt/c/Users/asier/dev/nftgram/web/node_modules/@types/.node-8MzkXP42 npm ERR! errno -13 npm ERR! Error: EACCES: permission denied, rename '/mnt/c/Users/asier/dev/nftgram/web/node_modules/@types/node' -> '/mnt/c/Users/asier/dev/nftgram/web/node_modules/@types/.node-8MzkXP42' npm ERR! [Error: EACCES: permission denied, rename '/mnt/c/Users/asier/dev/nftgram/web/node_modules/@types/node' -> '/mnt/c/Users/asier/dev/nftgram/web/node_modules/@types/.node-8MzkXP42'] { npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR!
syscall: 'rename', npm ERR! path: '/mnt/c/Users/asier/dev/nftgram/web/node_modules/@types/node', npm ERR! dest: '/mnt/c/Users/asier/dev/nftgram/web/node_modules/@types/.node-8MzkXP42' npm ERR! } npm ERR! npm ERR! The operation was rejected by your operating system. npm ERR! It is likely you do not have the permissions to access this file as the current user 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!
/home/asier/.npm/_logs/2021-04-29T10_48_16_436Z-debug.log

  • I've checked the ownership of that folder: ls -l/mnt/c/Users/asier/dev/nftgram/web/node_modules/@types/node, and I am the owner of all the files.

  • I've also tried to install it executing npm set unsafe-perm true but didn't work.

  • I've installed npm and node with NVM and I am using Windows 10 with Ubuntu on WSL.

npm -v: 7.11.1 node -v: v15.14.0 nvm --version: 0.34.0

The weird thing is that I can install other packages with no issues, I just installed react-hook-form for example.

I don't really know which can be the issue and I would be very happy if you guys can give me a clue!

Thank you beforehand for the help! :)



Solution 1:[1]

As I saw an error is related to permission. So you need to execute the command with the help of "sudo" like,

sudo npm install --save typescript @types/node @types/react @types/react-dom @types/jest

Solution 2:[2]

I had the same problem and the way to fix it was to stop my code that was running (webpack serve). In Windows you can't edit/delete files when those are in use. I think wsl may behave the same as it is a linux subsystem "inside" Windows.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Archana Agivale
Solution 2 valflrt