Search code examples
node.jsnpminstallationuninstallationreinstall

How to Reinstall Broken npm


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 WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8.
npm WARN npm You can find the latest version at https://nodejs.org/

I tried to do npm i -g npm but it couldn't update itself, it just kept throwing the same error above.

When I run npm -v it says 5.5.1 it seems the latest version is currently 5.8.0.

I tried deleting the folder and running the repair function on the node.js installer, but it didn't replace the module.


Solution

  • 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.