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条回答
Rolldiameter
2楼-- · 2019-01-08 08:43

Try following steps

1. Run this command on Terminal or CMD - npm cache clean

2. Go to this folder on windows %APPDATA%\npm-cache And delete folder which you want to install module (Ex:- laravel-elixir) or if you are using PowerShell, $env:APPDATA\npm-cache

3. Then Run your command EX:- npm install laravel-elixir

查看更多
趁早两清
3楼-- · 2019-01-08 08:43

$ npm cache clean
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.

I tried running npm cache verify with admin rights and it worked after that.

查看更多
太酷不给撩
4楼-- · 2019-01-08 08:44

Here is how I fixed the problem in Windows. I was trying to install the CLI for Angular.

  1. Turn off firewall and antivirus protections.

  2. Right click the nodejs folder (under Program Files), select Properties (scroll all the way down), click the Security tab, and click all items in the ALLOW column (for All System Packages and any user or group that allows you to add the “allow” checkmark).

  3. Click the Windows icon. Type cmd. Right click the top result and select Run as Administrator. A command window results.

  4. Type npm cache clean. If there is an error, close log files or anything open and rerun.

  5. Type npm install -g @angular/cli (Or whatever npm install command you are using)

  6. Check the installation by typing ng –version (Or whatever you need to verify your install)

Good luck! Note: If you are still having problems, check the Path in Environmental Variables. (To access: Control Panel → System and Security → System → Advanced system settings → Environment variables.) My path variable included the following: C:\Users\Michele\AppData\Roaming\npm

查看更多
趁早两清
5楼-- · 2019-01-08 08:47

You should run cmd.exe as administrator.

Follow the following steps:

  • Click Start, click All Programs, and then click Accessories.
  • Right-click Command prompt, and then click Run as administrator.
查看更多
甜甜的少女心
6楼-- · 2019-01-08 08:49

I was already running the Node Command Window as Administrator. As mentioned by many above, the following command with --f (force) solved my issue.

npm cache clean -f

After the Cache Clean, the install was flawless. See the screenshot for reference

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

Deleting the global npm-cache and/or running my cmd line as admin did not work for me. Also, as of npm version 5.x.x, it supposedly recovers from cache corruption by itself.

This did work:

1. Deleted the node_modules folder in my current project.

2. Deleted the package-lock.json in my current project

3. Installed the new package. In my case: npm install bootstrap@next --save

4. Ran npm install for my current project.

Everything now works. In general, nuking node_modules and package-lock.json usually fix these "no apparent reason" bugs for me.

EDIT

I just had the same problem again. But I noticed that everything was installed correctly even though it threw the error after I had followed the steps outlined above. So I could just run ng serve (for Angular), and everything worked.

This sure is a weird error...

查看更多
登录 后发表回答