Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Question: migrate global npm packages #481

Open
bfulop opened this issue Jun 23, 2021 · 9 comments
Open

Question: migrate global npm packages #481

bfulop opened this issue Jun 23, 2021 · 9 comments

Comments

@bfulop
Copy link

bfulop commented Jun 23, 2021

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!

@istevkovski
Copy link

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

@samhwang
Copy link

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

@ljharb
Copy link

ljharb commented May 16, 2022

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

@kraftwerk28
Copy link

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

@its-monotype
Copy link

Has anyone managed to create a script for windows PS?

@jryom
Copy link

jryom commented Dec 5, 2023

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.

@ljharb
Copy link

ljharb commented Dec 5, 2023

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.

@atwright147
Copy link

Is this a dupe of #139?

I made a suggestion to add a hooks system, which I think could be used to implement this in #1060

@romantech
Copy link

romantech commented Jun 16, 2024

I created a simple script and uploaded it to GitHub Gist. Running the command below will install the LTS version of Node.js and reinstall the global packages that are installed in the current Node.js version. You can also specify the Node.js version you want to install using the -v option.

curl -fsSL https://gist.githubusercontent.com/romantech/83ac87cea4e9a6d7a0985f610df329e5/raw/decd27fb4fb3c0aa6563a74e000dc00974f6f1e9/update-node-lts.sh | bash -s -- -v <version>

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants