EACCES error every time I try and do something with npm - node.js

Whenever I do anything related to npm, including uninstalling npm itself, I get this error:
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/local/bin/corepack
npm ERR! dest /usr/local/bin/.corepack-0KY6b4OJ
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/local/bin/corepack' -> '/usr/local/bin/.corepack-0KY6b4OJ'
npm ERR! [Error: EACCES: permission denied, rename '/usr/local/bin/corepack' -> '/usr/local/bin/.corepack-0KY6b4OJ'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rename',
npm ERR! path: '/usr/local/bin/corepack',
npm ERR! dest: '/usr/local/bin/.corepack-0KY6b4OJ'
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.
This didn't use to be the case as I have had no issues in the past, although the last time I tried to use an npm-related command was about a year ago.
I've tried many solutions, including sudo, nvm and uninstalling Node completely but nothing seems to work. I haven't used Node much before so I'm not very familiar with it unfortunately, so any help would be greatly appreciated.

run npm package as administrator by using the command
sudo npm install -g npm#latest

Turns out it was an issue with my antivirus software! After disabling the software and installing NVM everything now works fine.

Related

Installation of browser-sync on MAC rejected by OS

I Just installed node.js on my MAC and then tried to install browser-sync following the web instructions but got these errors but I don't know how to fix it. Could you help me solving it?
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/browser-sync
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/browser-sync'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/browser-sync'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/browser-sync'
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.```
As #iLuvLogix said in a comment, it was a matter of giving r/w permissions. After granting permissions I ran into the same problem several times (each time I run the installation command I got a new error on a different folder), so after each try I had to set new permissions until finally I got it installed completely. Annoying but effective.

npm install -g failing, getting npm ERR! code EACCES

When I run npm install -g typescript the following message shows:
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/typescript
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/typescript'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/typescript'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/typescript'
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! /Users/alexz/.npm/_logs/2021-12-26T10_45_08_412Z-debug.log
I tried to check if I have successfully installed TypeScript, if I run npm ls typescript it shows:
alexz# /Users/alexz
└── typescript#4.5.4
I am confused if I have installed TypeScript or not, because if I do tsc -v it tells me the tsc command is not found. How do I fix the above problem? Thanks!
It is a permission issue. You could read Resolving EACCES permissions errors when installing packages globally to change npm's permissions or you could use sudo command as below.
It may ask you your computer password.
sudo npm install -g typescript

npm install yarn not installing/ command not found

So im trying to use yarn for something (i dont really understand this stuff tbh) but within the project, I do npm install yarn and it does something with no errors, but yarn <anything> doesnt work and says command not found: yarn , and then npm install -g yarn (also --global) throws this error and have no clue why this happens. Not familiar with paths and what not either.
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/yarn
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/yarn'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/yarn'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/yarn'
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! /Users/*myname*/.npm/_logs/2021-11-27T21_44_09_137Z-debug.log
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.
Run the command as root (sudo npm install -g yarn) to install globally.

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! :)
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
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.

Why do I have this terminal issue when I try to install Sass?

I have difficulties in installing Sass.
I am using the Terminal, anyway, when i use npm install -g sass, I am getting error in log file. Here's which answer I receive:
npm WARN checkPermissions Missing write access to /Users/dagilo/desktop/npm-global/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /Users/dagilo/desktop/npm-global/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/Users/dagilo/desktop/npm-global/lib/node_modules'
npm ERR! [Error: EACCES: permission denied, access '/Users/dagilo/desktop/npm-global/lib/node_modules'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/Users/dagilo/desktop/npm-global/lib/node_modules'
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! /Users/admin/.npm/_logs/2021-02-01T14_18_27_655Z-debug.log
iMac-de-admin-3:Dagilo admin$ npm install -g sass
npm WARN checkPermissions Missing write access to /Users/dagilo/desktop/npm-global/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /Users/dagilo/desktop/npm-global/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/Users/dagilo/desktop/npm-global/lib/node_modules'
npm ERR! [Error: EACCES: permission denied, access '/Users/dagilo/desktop/npm-global/lib/node_modules'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/Users/dagilo/desktop/npm-global/lib/node_modules'
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! /Users/admin/.npm/_logs/2021-02-01T14_19_25_392Z-debug.log
Any idea how to solve this?
It's common permission issue in MAC OS so as log suggests you might need to use command sudo npm install -g sass to have privileges this installation requires.
Your log above says:
If you believe this might be a permissions issue, please double-check the permissions of the file and its containing directories, or try running the command again as root/Administrator.
In case you share computer or its company owned, you might need Administrator account or Administrator help to do so.
Additionally here is one relative answer and solution :NPM modules won't install globally without sudo

Resources