Npm Please try using this command again as root/administrator

后端 未结 30 724
旧巷少年郎
旧巷少年郎 2020-12-02 06:38

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 wi

相关标签:
30条回答
  • 2020-12-02 07:03

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

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

    0 讨论(0)
  • 2020-12-02 07:07

    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%\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.

    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)

    0 讨论(0)
  • 2020-12-02 07:07

    This is the flow often happens in this case. You run a command with no admin rights, you get message npm ERR! Please try running this command again as root/Administrator.. Then you open one more CLI(cmd, powershell, bash or whatever) and don't close the previous CLI. It appears you have 2 prompts opened in the same directory. And until you close CLI which runs with no admin rights you will be continuously getting npm ERR! Please try running this command again as root/Administrator. So close CLI which runs with no admins rights before running a new one.

    NOTE: a lot of IDE has embedded CLI(Visual Studio, VS Code etc) so please close the instance of IDE as well

    0 讨论(0)
  • 2020-12-02 07:08

    Here is how I fixed this on my Windows (7) Dev. environment. I assume the following...

    • You are Running Command Prompt, Git Bash, Cmder or your favorite Terminal, as an Administrator by right clicking
    • Privileges Permissions have been granted for Read/Write (i.e chmod -777)

    Okay, let's get to it:

    1. Update any packages where a version check is returning a warning ("npm WARN"..) for example...

      npm update -g npm

      npm update -g graceful-fs

    2. Next we want to force a cache clean. This is flagged by an '--f' or '-f'..

      npm cache clean --f

    3. In Widows Explorer search for the following path

    %APPDATA%\npm-cache

    And Delete it's contents

    1. Start a fresh instance of your Terminal, remembering to 'Right-Click' and 'Run as Administrator', install the packages again.

    Hope this helps someone!!

    0 讨论(0)
  • 2020-12-02 07:09

    I had the same problem, what I did to solve it was ran the cmd.exe as administrator even though my account was already set as an administrator.

    0 讨论(0)
  • 2020-12-02 07:09
    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

    0 讨论(0)
提交回复
热议问题