Managing node versions can become painful when switching between projects.
There’s a mechanism to check node versions during an npm install
called
Engines, but that doesn’t help if the projects are installed already.
The fix is to install node as a dependency. Who would have thought?
Let’s say you have several projects you’re working on for clients and each one has different versions of node.
The current way of working (for me anyway) is to use
NVM to switch versions of node.
It works, but is tedious and can become confusing.
npm install node@<version> --save-dev
That’s it. Any npm commands are then run using the locally installed node version.
My currently installed version of node is 10.15.3, so running node -v
as part of an npm script gives me the following:
After installing node as a dependency, the build uses the local version instead!
Enjoy!