macosnpmjhipsteryarnpkgyo

Yarn package won't upgrade globally (after migrating from NPM)


I was trying to run yarn global upgrade generator-jhipster but even though it seemed like it was working and installing the latest version, when I would run yo jhipster It would still be on an old version and would prompt me to run yarn global upgrade generator-jhipster

I was running on OSX (Mac)

I had just recently started using Yarn. I was previously using NPM but uninstalled NPM.

$HOME/.config/yarn/global/node_modules/.bin was in my path, so that wasn't the issue.


Solution

  • When I switched over from NPM to Yarn, I did not remove the packages installed by NPM before uninstalling NPM. So, when adding global packages via Yarn, the symlinks were still associated with the NPM installations. This caused me to have issues globally upgrading/adding the packages through Yarn, since it wasn't pointing to the new versions managed by Yarn.

    (I had installed Node and NPM via Homebrew and this is how I ended up reinstalling NPM:)

    brew uninstall --force yarn
    brew uninstall --force node
    brew install node
    

    Then I removed all of NPM's global modules since I wanted to exclusively use Yarn now. (Make sure you really want all of these removed before you do this! You might want to run npm list -g --depth=0 to see what NPM was managing for you, so you can reinstall with Yarn) (This does not work on Windows, for a Windows version, see Ollie Bennett's Answer

    npm ls -gp --depth=0 | awk -F/ '/node_modules/ && !/\/npm$/ {print $NF}' | xargs npm -g rm
    

    Here is how it works: Taken from Kai Sternad's Answer

    Then, reinstalled yarn. brew install yarn

    Be sure you have $HOME/.config/yarn/global/node_modules/.bin in your path. (see Yarn Path Setup

    On Mac or Linux:

    export PATH="$PATH:`yarn global bin`:$HOME/.config/yarn/global/node_modules/.bin"
    

    Then installed yo and generator-jhipster (I had already removed these via Yarn) (see Installing JHipster)

    yarn global add yo
    yarn global add generator-jhipster
    

    Add it was finally globally updated to the latest version!