How to Reinstall Broken npm

前端 未结 4 869

I just installed node v9.11.1 when I try to use npm I keep getting the following error:

npm WARN npm npm does not support Node.js v9.11.1
npm W         


        
相关标签:
4条回答
  • 2020-12-03 08:09

    Delete the Global NPM Folder

    https://stackoverflow.com/a/5926706/349659

    npm list -g
    

    For Windows this will most likely be:

    %AppData%\npm\node_modules

    You can paste that into a folder's address bar and it will take you there.

    Once there delete the folder named npm.

    Download the Latest Release of NPM

    https://github.com/npm/cli/releases/latest

    Grab the zip and unzip it to your node_modules folder that you just deleted the npm folder from.

    Rename the folder you extracted from the zip to npm

    If you get any warnings about the file path or name being too long skip the warnings.

    Update for Good Luck

    Now you should be able to run npm i -g npm to update/reinstall npm without any warnings.

    I find this step especially important if you had errors in Windows about the path or file name being too long.

    You may get the following errors. If you do go and delete or move the files it has listed and you should be able to run npm i -g npm successfully.

    npm ERR! Refusing to delete C:\Program Files\nodejs\npx.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
    npm ERR! File exists: C:\Program Files\nodejs\npx.cmd
    npm ERR! Move it away, and try again.
    
    npm ERR! Refusing to delete C:\Program Files\nodejs\npm.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
    npm ERR! File exists: C:\Program Files\nodejs\npm.cmd
    npm ERR! Move it away, and try again.
    
    0 讨论(0)
  • 2020-12-03 08:12

    Try this command to reinstall npm

    npm install -g npm-reinstall
    

    If you are using a linux distribution add sudo

    sudo npm install -g npm-reinstall
    
    0 讨论(0)
  • 2020-12-03 08:21

    Try this:

    npm install npm@latest -g
    

    More info here.

    0 讨论(0)
  • 2020-12-03 08:24

    For me even deleting npm folder or reinstalling Node didn't help. After updating Nodejs and npm to latest version (Node 10.19, npm 6.14.3) of my CentOS 6, I've got constant libs error with npm while Node was fine.

    What's worked - n Node version manager. With this command I could reverse my npm version: n -p 6.13 link

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