fnm icon indicating copy to clipboard operation
fnm copied to clipboard

Question: migrate global npm packages

Open bfulop opened this issue 4 years ago • 12 comments

Hello,

Thank you for this great tool!

I was wondering, what's the "recommended" way to migrate globally installed npm packages when moving from one version to another?

Thanks again!

bfulop avatar Jun 23 '21 10:06 bfulop

I second this, can we push for this to happen?

istevkovski avatar Mar 09 '22 08:03 istevkovski

I believe the nvm way of doing this was to:

  • nvm use <node version>
  • nvm copy-packages <node version that has the global packages you want to migrate from>
  • nvm will then migrate those global packages (with the same versions) to the node version you're using.

I'd love to see fnm having this capability as well! <3

samhwang avatar May 15 '22 23:05 samhwang

It’s nvm reinstall-packages Y since that’s a more accurate name :-) (and nvm install X --reinstall-packages-from=Y)

It will reinstall packages as well as copy over symlinks (from npm link).

ljharb avatar May 16 '22 00:05 ljharb

I use this for migrating global packages (assuming we are currently on the newer version):

fnm_upgrade () {
  fnm exec --using=$1 npm ls --global --json \
    | jq -r '.dependencies | to_entries[] | .key+"@"+.value.version' \
    | xargs npm i -g
}

# Usage:
$ fnm_upgrade 18.4

kraftwerk28 avatar Oct 26 '22 22:10 kraftwerk28

Has anyone managed to create a script for windows PS?

its-monotype avatar Dec 04 '23 22:12 its-monotype

I switched to pnpm for global packages, which sort of solved this issue for me as pnpm keeps packages in a global folder, not tied to a particular version of node. Might be helpful for someone else as well.

jryom avatar Dec 05 '23 08:12 jryom

That’s surprising since global packages must be tied to a particular version of node, since installed and compiled packages can differ based on the node version.

ljharb avatar Dec 05 '23 15:12 ljharb

Is this a dupe of https://github.com/Schniz/fnm/issues/139?

I made a suggestion to add a hooks system, which I think could be used to implement this in https://github.com/Schniz/fnm/issues/1060

atwright147 avatar Dec 06 '23 15:12 atwright147