Ever been tempted to smash your laptop from yet another Node version conflict from tooling hell? Volta is for you.
Suppose you have two projects, each requiring their own version of node. First install volta: brew install volta
Project 1
volta setup
volta install node@14
volta install yarn
yarn install
cd /path/to/project-using-node-14
node -v
v14.17.0
Project 2
volta setup
(optional; alreadyvolta install node@16.1.0
volta install yarn
yarn install
cd /path/to/project-using-node-16
node -v
v16.1.0
How does Volta work?
Rather than changing your node version system-wide, Volta simply shims the tools you need for each project directory. This feels like a lifesaver if you’re running Apple silicon / m1 chip on a new Macbook. Also, Volta runs FAST. Better yet: Volta ensures even global dependencies respect the requirements of your package.
For example, installing the Typescript package:
npm install --global typescript
Depending on the project you’re in, this executable will switch to the project’s chosen version of TypeScript:
cd /path/to/project-using-typescript-3.9.4
tsc --version # 3.9.4cd /path/to/project-using-typescript-4.1.5
tsc --version # 4.1.5
You can also specify your tooling within your package.json
:
"volta": { "node": "14.17.0", "yarn": "1.22.10"}
Other developers
Others can use volta setup
without ever having to lookup what version of node the project needs. In other words: once you setup a project, Volta gets tooling out of your way and you don’t have to think about it anymore.
A word about Brew conflicts
Volta handles node
, yarn
, and global dependencies. If you previously installed any of those tools via brew
you will want to brew uninstall
them and let Volta handle it to avoid conflicts. This is actually the benefit of using Volta.
Why not use NVM?
- NVM explicitly disavows the use of
brew
. - NVM can’t rely on engine versions inside
package.json
(requires.nvmrc
file) - NVM doesn’t handle all your tooling
It’s not so much that NVM is bad. It’s just that Volta is much better. Enjoy!