Closed pallatee closed 8 years ago
I was able to solve this by going in the /usr/local/lib/node_modules/npm, and giving myself read and write permissions there. Then the same thing in /users/ME/.npm/_locks. Not sure why i didn't already have permissions in the last instance.
npm 2.5.1
@vickerym are you running NVM or no? I have all those permissions I believe but still had the issue.
@joeRob2468 thanks a bunch! Worked like a charm!
@vinifala thanks that worked for me!
I was not able to fix this problem with any of the above solutions (unsafe-perm, prefix, etc.). I do believe the issue is with open filehandles. I installed yarn and it worked straight away.
If your workspace has package-lock.json
please remove and try again to npm i
. It might work, since i had a same issue in MS.
Fixed my install with NVM
and NPM 8.8.0
using:
sudo chown -R u:p node_modules
sudo chown -R u:p u/.nvm
Where u
is username and p
is password. Had to do this on both directories! Thanks for the tips above, chmod
wouldn't do.
Hope that helps someone!
PS - that was in the root directory of the project and root directory of WSL, respectively.
@jgchristopher Thank You :+1: npm config set unsafe-perm=true worked for me :)
sudo chown -R myusername: /usr/local/lib/node_modules
This solved my issue
@jgchristopher Thank You 👍 npm config set unsafe-perm=true worked for me :)
npm ERR! path E:\angulartemplate\coreui-free-angular-admin-template-master\coreui-free-angular-admin-template-master\node_modules.staging\end-of-stream-07f5179b\index.js npm ERR! code EPERM npm ERR! errno -4048 npm ERR! syscall unlink npm ERR! Error: EPERM: operation not permitted, unlink 'E:\angulartemplate\coreui-free-angular-admin-template-master\coreui-free-angular-admin-template-master\node_modules.staging\end-of-stream-07f5179b\index.js' npm ERR! { Error: EPERM: operation not permitted, unlink 'E:\angulartemplate\coreui-free-angular-admin-template-master\coreui-free-angular-admin-template-master\node_modules.staging\end-of-stream-07f5179b\index.js' npm ERR! cause: npm ERR! { Error: EPERM: operation not permitted, unlink 'E:\angulartemplate\coreui-free-angular-admin-template-master\coreui-free-angular-admin-template-master\node_modules.staging\end-of-stream-07f5179b\index.js' npm ERR! errno: -4048, npm ERR! code: 'EPERM', npm ERR! syscall: 'unlink', npm ERR! path: 'E:\angulartemplate\coreui-free-angular-admin-template-master\coreui-free-angular-admin-template-master\node_modules\.staging\end-of-stream-07f5179b\index.js' }, npm ERR! stack: 'Error: EPERM: operation not permitted, unlink \'E:\angulartemplate\coreui-free-angular-admin-template-master\coreui-free-angular-admin-template-master\node_modules\.staging\end-of-stream-07f5179b\index.js\'', npm ERR! errno: -4048, npm ERR! code: 'EPERM', npm ERR! syscall: 'unlink', npm ERR! path: 'E:\angulartemplate\coreui-free-angular-admin-template-master\coreui-free-angular-admin-template-master\node_modules\.staging\end-of-stream-07f5179b\index.js', npm ERR! parent: '@coreui/coreui-free-angular-admin-template' } 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 (though this is not recommended).
npm config set unsafe-perm=true
In my case it was VS Code locking a file in node_modules. Closing VS code unlocked the file and made the error go away. npm config set unsafe-perm true
, disabling antivirus etc. did not work.
If npm config set unsafe-perm=true
isn't working
Just try updating npm npm install -g npm
It is not recommended to use sudo
when installing npm packages.
Similarly, npm config set unsafe-perm true
should be avoided.
Regardless of security concerns, neither option is necessary. A better solution:
mkdir ~/.npm-global
npm config set prefix ~/.npm-global
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
sudo
:
npm install -g pnpm
You can skip steps 2-4 if you prefer not to modify ~/profile by setting an ENV variable:
NPM_CONFIG_PREFIX=~/.npm-global
Things work better for me when I set fewer environment variables.. YMMV.
Tested with:
Reference => official NPM docs:
FWIW our team was having this problem intermittently trying to npm install
on a mounted windows directory and were pulling our collective hair out re-installing node, checking versions, etc. It turns out it was just because we were all using vscode with the folder open in a workspace. You also need to make sure you don't have any running node processes (dev server, watching build script, etc). Once I shut all of those down I stopped getting the errors. I do suspect that there are many root causes of this issue though, and open file handles are just one of them.
Although, I'm using Ubuntu, I tried cleaning npm cache
sudo npm cache clear --force
and then it allowed me to run without sudo
npm i
The other options didn't work for me and I can't asure that this is the best option.
Fixed my install with
NVM
andNPM 8.8.0
using:sudo chown -R u:p node_modules sudo chown -R u:p u/.nvm
Where
u
is username andp
is password. Had to do this on both directories! Thanks for the tips above,chmod
wouldn't do.Hope that helps someone!
PS - that was in the root directory of the project and root directory of WSL, respectively.
'p' should be the group, not the password. If you put that as your password, anybody can see your password by viewing the file stats !!!!!
I've successfully worked around this issue, letting for example cordova function correctly.
My fix is at https://github.com/fuzzyTew/nodejswslfix . The library must be compiled by hand and preloaded into npm's environment, and it intercepts the problematic call, providing a quick fix to this issue.
npm would be able to resolve this issue by altering their concurrent behavior when moving multiple submodules out of the staging folder. I haven't mentioned it to them or looked at the npm code, myself.
^--- Added some discussion in #1529 since it has the virtue of still being open.
@borovaka you can fix that error by allowing unsafe perms
npm config set unsafe-perm=true
working ......thanks man
I tried every single solution posted in this issue but none of them worked, but I did find a way to make things work again...
For me personally I was just trying to update npm module so I downloaded the latest nodejs binary from their website and unpacked it on windows, then I did
sudo rm -rf /usr/lib/node_modules/npm
in subsystem and copied only npm binary in the archive to the same place using Windows Explorer, and finally I
sudo chmod a+x /usr/bin/npm
Now npm is up to date without updating nodejs along with it!
For anyone who tried other solutions here but didn't work :)
EDIT: to open Windows Explorer in current directory is explorer.exe .
and you can navigate to root directory from there.
If it helps anyone I've traced it down to having vscode-insider open while npm installing.
When it's turned off, it appears to work fine. It might have something to do with the watchers.
This solved all my EACESS problem (on MAC):
sudo chown -R myusername: /Users/myusername/.npm/
@allain I can confirm this. Just shut down VSC Insider and my npm install worked fine.
If it helps anyone I've traced it down to having vscode-insider open while npm installing.
When it's turned off, it appears to work fine. It might have something to do with the watchers.
Yep. Confirmed here too
This fixed my issue
sudo chown -R $USER ~/.npm
Using MacOS Mojave
hey guys , if you using mac try running the command with sudo . it may help alot :)
This solved all my EACESS problem (on MAC):
sudo chown -R myusername: /Users/myusername/.npm/
Confirmed here too. Closed code-insiders and the error went away. Thanks so much.
If it helps anyone I've traced it down to having vscode-insider open while npm installing.
When it's turned off, it appears to work fine. It might have something to do with the watchers.
Same here as well. Win 10 WSL Ubuntu 18.04. Once I close code-insider it works like a charm.
This issue seems to come when changes are made to package.json file without npm knowing about it. Just do a plain npm install. Then install your module again. It should work. This is one of the scenarios that worked for me. There might be other issues causing similar problems.
@hajimurtaza :
This issue seems to come when changes are made to package.json file without npm knowing about it. Just do a plain npm install. Then install your module again. It should work.
You're wrong there. This issue occurs when VSCode / VSCode Insiders is open in the project folder and you're trying an npm install
.
@hajimurtaza : This issue seems to come when changes are made to package.json file without npm knowing about it. Just do a plain npm install. Then install your module again. It should work.
You're wrong there. This issue occurs when VSCode / VSCode Insiders is open in the project folder and you're trying an
npm install
.
There is no one specific scenario that is triggering this issue. It happens for different reasons for different people: from VSCode & other apps being open, from npm installation ordering details, or from permissions settings. Some problems can be resolved by closing or changing something, but some are deeply rooted in the issue.
@hajimurtaza : This issue seems to come when changes are made to package.json file without npm knowing about it. Just do a plain npm install. Then install your module again. It should work.
You're wrong there. This issue occurs when VSCode / VSCode Insiders is open in the project folder and you're trying an
npm install
.There is no one specific scenario that is triggering this issue. It happens for different reasons for different people: from VSCode & other apps being open, from npm installation ordering details, or from permissions settings. Some problems can be resolved by closing or changing something, but some are deeply rooted in the issue.
Updated the answer.
I had node_modules installed before i installed nvm on the projet directory. Deleting them and running npm install
worked for me.
My issue was that npm
existed on both my Windows installation and my WSL instance. When I uninstalled NodeJS from WSL, and ran npm
, it would find and execute the Windows one. This leads me to believe that somewhere in the chain, the wrong npm
was being called which doesn't really have access to certain parts of the WSL file system.
I solved it my issue by removing NodeJS from Windows. Alternatively, I could have removed %APPDATA%\Roaming\npm
from the PATH
system environment. Or simply, disabling AppendNtPath
in the registry:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss]
"AppendNtPath"=dword:00000000
This is a known issue with VSCode remoting and WSL (Microsoft/WSL#3395, Microsoft/WSL#1956) and should be fixed in WSL2.
This is caused because VSCode remoting watches files, which prevents them from being accessed elsewhere. The fix is to tell VSCode to poll when remote instead of watch. See below:
ctrl+shift+p
then type & select Preferences: Open Settings (JSON)
."remote.WSL.fileWatcher.polling": true
to the configctrl+shift+p
then type & select Developer: Reload Window
.For more information, see the documentation on VSCodes website regarding EACESS.
first run sudo su (as a root/administrator) and run npm install -g typescript as a root/administrator y.. worked for me
If you are on windows, re-installing IIS on my solved the problem for me.
I've discovered it's an issue with open handles. VSCode can hold handles for longer than it should. Trying a command in just a bash shell open in Powershell can give EACESS errors. The act of just closing VSCode and trying the command again the bash shell works.
This has happened even when I close the related workspace on VSCode. The handle seems to only release when I actually close VSCode.
That doesn't make much sense, but perhaps the WSLv1 filesystem isn't properly closing files, or perhaps some logic faulty when a file handle is open and another tries to delete it?
It turns out it was just because we were all using vscode with the folder open in a workspace
This fixes it.
Got the same issue today running npm install -g gatsby-cli
on WSL 2.
npm config set unsafe-perm true
and npm config set unsafe-perm=true
couldn't solve the problem.
I also didn't had my VSC open.
sudo chown -R $(whoami) ~/.npm
and sudo chown -R $(whoami) /usr/lib/node_modules
got me further but didn't solve the problem since gatsby wants to write into /usr/bin/gatsby
.
Had to sudo it.
After following this this and this tutorials, I was able to install it without sudo.
Turns out it was just a matter of using nvm.
Got the same issue today running
npm install -g gatsby-cli
on WSL 2.
npm config set unsafe-perm true
andnpm config set unsafe-perm=true
couldn't solve the problem.I also didn't had my VSC open.
sudo chown -R $(whoami) ~/.npm
andsudo chown -R $(whoami) /usr/lib/node_modules
got me further but didn't solve the problem since gatsby wants to write into/usr/bin/gatsby
.Had to sudo it.
After following this this and this tutorials, I was able to install it without sudo.
Turns out it was just a matter of using nvm.
Yes, you're installing it globally so you need to use sudo
. NVM can indeed go around it since the packages are installed in your home folder instead.
Using sudo
worked.
sudo npm install -g npm@latest
# Remove nvm
rm -rf $HOME/.nvm
# Install latest nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
Latest install script can be found https://github.com/nvm-sh/nvm#install--update-script
I just ran WSL as admin and everything seems to be okay.....for now :) So now I am able to rum rm -rf npm install etc.
cheeers
It turns out it was just because we were all using vscode with the folder open in a workspace
This fixes it.
Yes. For me too. To be clearer: I closed VSCode. Instead of using VSCode integrated terminal, I used the Ubuntu 18.04 LTS app directly (in Windows, this opens a terminal).
@allain I can confirm this. Just shut down VSC Insider and my npm install worked fine.
great! thanks!!
Figured you don't even have to close VSC, just make sure the directory is not currently open in the files list. Thanks for the tip!!!
npx [package] example to Ionic: npx ionic
While trying to install a packge with npm (for example lodash) it fails with error message:
I have tried to install it both with and without starting bash in administrator mode.