Npm Please try using this command again as root/ad

2019-01-08 08:12发布

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:\Sergiu\Knockout Test
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! path D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\block-stream\block-stream.js
npm ERR! fstream_path D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\block-stream\block-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:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\block-stream\block-stream.js'
npm ERR! fstream_stack C:\Program Files\nodejs\node_modules\npm\node_modules\fstream\lib\writer.js:284:26
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! Error: EPERM, lstat 'D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\fstream\LICENSE'
npm ERR!  { [Error: EPERM, lstat 'D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\fstream\LICENSE']
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.

28条回答
该账号已被封号
2楼-- · 2019-01-08 08:35
  1. Close the IDE
  2. Close the node terminals running ng serve or npm start
  3. Go to your project folder/node_modules and see you if can find the package that you are trying to install
  4. If you find the package you are searching then delete package folder
  5. In case, this is your 1st npm install then skip step 4 and delete everything inside the node_modules. If you don't find node_modules then create one folder in your project.
  6. Open the terminal in admin mode and do npm install.

That should fix the issue hopefully

查看更多
聊天终结者
3楼-- · 2019-01-08 08:36

If you're in react native project, and Expo is running, then close it.

Re-install the package, and everything should be fine.

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-08 08:38

A solution that worked, is to close all PowerShell and cmd instances. Start PowerShell/cmd again as administrator and things seem to work.

This can happen if you're doing react-native and the node.js cmd is open in the background.

查看更多
甜甜的少女心
5楼-- · 2019-01-08 08:39

As my last resort with this error I created a fresh windows 10 virtual machine and installed the latest nodejs (v6). But there was a host of other "ERRs!" to work through.

I had to run npm cache clean --force which ironically will give you a message that reads "I sure hope you know what you are doing". That seems to have worked.

It doesn't solve the issue on my main Dev machine. I'm canning nodejs as I found over the last few years that you spend more time on fixing it rather than on actual development. I had fewer issues with node on linux ubuntu 14.04 if that's any help.

查看更多
别忘想泡老子
6楼-- · 2019-01-08 08:41

WHAT WORKED FOR ME

I ran Command Prompt as Administrator. This helped partially - as I no longer got the error, "Please try using this command again as root/administrator". I was trying to install Cordova. To do it successfully, I also had to do the following:

(1) "npm update node", plus...

(2) I also added the " -g " in the >>npm install cordova<<. In other words, type this: >>npm install -g cordova<<

~~~ FOR WINDOWS 8.1 ~~~

"RUN AS ADMINISTRATOR" COMMAND PROMPT

For windows 8.1, I don't have an ACCESSORIES group when I click START > ALL PROGRAMS. But I do have that older -- but trusty and reliable -- START BUTTON and START MENU - thanks to the free Classic Start Menu app. So, with that installed....

ALTERNATIVE #1:

1. Type "cmd" in the SEARCH BOX at the bottom of the START menu.  
2. When cmd.exe shows up in the top of the search results, right click it and select RUN AS ADMINISTRATOR.

ALTERNATIVE #2 If you already have a Command Prompt window open and running - and you want to open another one to Run As Administrator:

1. Locate the Command Prompt app icon in the Taskbar (usually along the bottom of you screen unless you have moved it a different dock/location).
2. Right click the app icon.
3. Now, right click "COMMAND PROMPT" and select RUN AS ADMINISTRATOR. 

Hope this helps someone.

查看更多
小情绪 Triste *
7楼-- · 2019-01-08 08:42

What helped me on Windows 10 was just ticking off "Read Only" of project node_modules.

查看更多
登录 后发表回答