Udostępnij za pośrednictwem


How to fix Node.js npm permission problems

With node version 0.6.10 and npm version 1.1.0-3, you may run into this error when installing a module on Windows, not just the Azure module:

 PS> npm install azure
npm http GET https://registry.npmjs.org/azure
npm http 200 https://registry.npmjs.org/azure
npm http GET https://registry.npmjs.org/azure/-/azure-0.5.2.tgz
npm http 200 https://registry.npmjs.org/azure/-/azure-0.5.2.tgz
npm ERR! Could not unpack C:\Users\Matt\AppData\
  Roaming\npm-cache\azure\0.5.2\package.tgz 
  to C:\Users\Matt\AppData\Roaming\npm-cache\azure\0.5.2

npm ERR! Error: EPERM, operation not permitted 
  'C:\Users\Matt\AppData\Roaming\npm-cache\
  azure\0.5.2\___package.npm\package'
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR!
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files (x86)\\nodejs\\\\node.exe" 
  "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\
  npm-cli.js" "install" "azure"
npm ERR! cwd C:\Users\Matt\Documents\src\node
npm ERR! node -v v0.6.10
npm ERR! npm -v 1.1.0-3
npm ERR! path C:\Users\Matt\AppData\Roaming\npm-cache\
  azure\0.5.2\___package.npm\package
npm ERR! code EPERM
npm ERR! message EPERM, operation not permitted 
  'C:\Users\Matt\AppData\Roaming\npm-cache\
  azure\0.5.2\___package.npm\package'
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\Users\Matt\Documents\src\node\npm-debug.log
npm not ok

It turns out that you don’t have to run the command again as Administrator, and doing so won’t fix the problem.  Try npm cache clean first.  If that doesn’t fix things, take a look in %APPDATA%\npm-cache, or if you’re using PowerShell, $env:APPDATA\npm-cache.  After cleaning the cache, you may still be left with remnants.  Manually remove everything in that directory, and try again.  This has always fixed things for me.

Comments

  • Anonymous
    February 04, 2014
    thank you so much! npm cache clean fixed my problem! works now.

  • Anonymous
    April 03, 2014
    Worked for me too. Thank you ! And I made small pull request to npm according to this. github.com/.../5005

  • Anonymous
    May 09, 2014
    I was having the same issues, but your solution did not wok for me... but I kept trying and my answer is here stackoverflow.com/.../23569456

  • Anonymous
    June 18, 2014
    I was trying to use Command Prompt to install mongojs, but always received the same error. I searched all over for a solution to this problem, but mostly found Linux related issues. Running npm in the Command Prompt was the issue (I got the same error when trying to clear the cache), apparently, because when I tried in PowerShell, it worked perfectly. Thanks so much for your help.

  • Anonymous
    July 29, 2014
    also if you're a complete troglodyte like me try to check if your firewall isn't blocking npm

  • Anonymous
    September 20, 2014
    Thanks so much, works like a charm!