npm 6 vs npm 7 lockfileVersion
I started to get lockfileVersion: 2
(generated by npm 7) in one of the repos that I work with. We have not migrated over yet so I really need to do get that repo running with npm 6.
but don’t we use nvm?
In our repos we use .nvmrc
to lock Node versions, so before doing any operations we run nvm use
. But this only ensured I used the correct Node version, but not NPM.
// this is in the problematic repo
% nvm use
Now using node v12.16.1 (npm v7.8.0)
// this is in another repo which is fine
% nvm use
Now using node v14.16.1 (npm v6.14.12)
a globally-installed node
Based on this comment on NodeJS github, it seems like npm 7 will be shipped only with node 16 (LTS version) onwards. It is also bundled with based on the release notes on Node.JS.
After some googling with no immediate answer, a colleague shed some light: “The only way node 12 would be using 7 is if you have globally updated it”.
After some searching I also found this comment that verified there is a way to use the latest npm
, even though not bundled with the node version, by “upgrading in runtime via npm install -g npm@latest
“.
😱
How did I get to this state, since, of course (sacarstically) I always use nvm
to manage node versions?!
solution
Firstly, confirming node 12 and npm 7 were globally installed in various terminals:
% node -v v12.16.1
% npm -v 7.8.0
Then, took a few attempts to figure out how to uninstall successfully (since I don’t know how I got them installed globally in the first place):
% npm uninstall -g npm@7 😬
// Can't remember what the outcome was, maybe claiming to be "successful" but actually not
% brew uninstall node
Refusing to uninstall /usr/local/Cellar/node/15.13.0
because it is required by yarn, which is currently installed.
You can override this and force removal with:
brew uninstall --ignore-dependencies node
// why is it uninstalling 15.13.0??
% cd /usr/local/Cellar/node/
% ls
15.13.0
// hmmm, maybe not that folder then.
// maybe for another time why I have node 15 installed with brew.
% which node
/Users/some_paths/.nvm/versions/node/v12.16.1/bin/node
// ah, maybe this here. looks like it's under nvm?
// change the active node version
% nvm use 14
Now using node v14.16.1 (npm v6.14.12)
% nvm uninstall v12.16.1
Uninstalled node v12.16.1
% node -v
v14.16.1
% npm -v
6.14.12
// Woohoo, SUCCESS!