Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

windows - Npm Please try using this command again as root/administrator

I've been desperately trying to install modules using node.js but it always fails getting packages with npm.

I logged in as Administrator and used powershell/cmd with "run as administrator". I also had problems with the registry so I used npm set registry http://registry.npmjs.org/

I tried everything... it just drives me nuts.

Here are the errors:

npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "generator-knockout"
npm ERR! cwd D:SergiuKnockout Test
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! path D:SergiuKnockout Test
ode_modulesgenerator-knockout
ode_modulesyeoman-generator
ode_modulesar
ode_moduleslock-streamlock-stream.js
npm ERR! fstream_path D:SergiuKnockout Test
ode_modulesgenerator-knockout
ode_modulesyeoman-generator
ode_modulesar
ode_moduleslock-streamlock-stream.js
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! code EPERM
npm ERR! errno 50
npm ERR! stack Error: EPERM, lstat 'D:SergiuKnockout Test
ode_modulesgenerator-knockout
ode_modulesyeoman-generator
ode_modulesar
ode_moduleslock-streamlock-stream.js'
npm ERR! fstream_stack C:Program Files
odejs
ode_modules
pm
ode_modulesfstreamlibwriter.js:284:26
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! Error: EPERM, lstat 'D:SergiuKnockout Test
ode_modulesgenerator-knockout
ode_modulesyeoman-generator
ode_modulesar
ode_modulesfstreamLICENSE'
npm ERR!  { [Error: EPERM, lstat 'D:SergiuKnockout Test
ode_modulesgenerator-knockout
ode_modulesyeoman-generator
ode_modulesar
ode_modulesfstreamLICENSE']
npm ERR!   errno: 50,
npm ERR!   code: 'EPERM',
npm ERR!   path: 'D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\fstream\LICENSE',
npm ERR!   fstream_type: 'File',
npm ERR!   fstream_path: 'D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\fstream\LICENSE',
npm ERR!   fstream_class: 'FileWriter',
npm ERR!   fstream_stack:
npm ERR!    [ 'C:\Program Files\nodejs\node_modules\npm\node_modules\fstream\lib\writer.js:284:26',
npm ERR!      'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It turns out that you don’t have to run the command again as Administrator, and doing so won’t fix the problem.

Try:

  1. npm cache clean first.

  2. If that doesn’t fix things, take a look in %APPDATA% pm-cache, or if you’re using PowerShell, $env:APPDATA pm-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.

As @Crazzymatt was mentioning, as of the npm@5 version and up, we need to use npm cache verify instead of npm cache clean. Or else you will get an error as preceding.

npm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead.

(Source: MSDN Blog post)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...