nodejs / corepack

Zero-runtime-dependency package acting as bridge between Node projects and their package managers
MIT License
2.61k stars 172 forks source link

How to update/upgrade from older version? #166

Open digeomel opened 2 years ago

digeomel commented 2 years ago

I am using yarn 1.22.19 with node 14.19.1 (actually using nvm to be able to use multiple node versions, but I'm not sure this is important here). I assume yarn installed corepack 0.10.0, because I definitely didn't install it manually myself. How can I upgrade to the latest version 0.13.0? Do I need to uninstall yarn first? I tried with npm and it fails with the following error:

npm WARN rm not removing /home/digeomel/.nvm/versions/node/v14.19.1/bin/yarn as it wasn't installed by /home/digeomel/.nvm/versions/node/v14.19.1/lib/node_modules/corepack
npm WARN rm not removing /home/digeomel/.nvm/versions/node/v14.19.1/bin/yarnpkg as it wasn't installed by /home/digeomel/.nvm/versions/node/v14.19.1/lib/node_modules/corepack
npm ERR! code EEXIST
npm ERR! path /home/digeomel/.nvm/versions/node/v14.19.1/bin/corepack
npm ERR! Refusing to delete /home/digeomel/.nvm/versions/node/v14.19.1/bin/corepack: ../lib/node_modules/corepack/dist/corepack.js symlink target is not controlled by npm /home/digeomel/.nvm/versions/node/v14.19.1/lib/node_modules/corepack
npm ERR! File exists: /home/digeomel/.nvm/versions/node/v14.19.1/bin/corepack
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
aduh95 commented 2 years ago

I assume yarn installed corepack 0.10.0, because I definitely didn't install it manually myself.

It's most likely not Yarn that did that, nvm probably installed Corepack, Corepack 0.10.0 is bundled with Node.js v14.19.1.

I tried with npm and it fails with the following error:

What did you try exactly? It'd be helpful to see the command you used.

digeomel commented 2 years ago

@aduh95 I think it's obvious, but here goes:

npm -g install corepack@0.13.0

aduh95 commented 2 years ago

It seems that nvm has a install-latest-npm feature (https://github.com/nvm-sh/nvm#migrating-global-packages-while-installing), maybe that also upgrades Corepack (although I doubt it, Corepack is nowhere to be seen in their docmentation). If that doesn't work, I think you would need to open an issue to nvm and/or install Node.js from a different source that lets you chose whether you want the vendored version of Corepack alongside it. FWIW waiting for the next non-security release of Node.js v14.x is also an option, as it will include an updated version of Corepack, but I don't know when that's going to happen.

merceyz commented 2 years ago

As the npm error tells you, it refuses to overwrite something it didn't create, you can add the -f flag to force it.

npm -g -f install corepack@0.13.0