Volta solves the problem of global packages
What is the “problem of global packages”?
You can categorize these tools into three categories:
- The runtime, that would be Node.js
The problem of global packages
The problems of global packages are slightly different for the three categories mentioned above.
This can be done via a script whenever you enter the directory via command-line but the switch can be slow and any global packages you installed for one version are now not available anymore or might break because they depend on a specific version to work.
A certain Node version comes with a certain npm version. Yarn global installs might require a certain Node version or just possibly not work with a certain version of Node.
Some projects might need different versions of package managers because they might rely on features that are differ between the version.
Global npm packages
- It is installed for the currently active Node version. That means it is not available when you switch to a different version.
- Or it just uses whichever Node version is currently active which creates reliability issues because it might not be compatible for this version. In some cases it even needs to be recompiled.
Volta solves all of this and gets out of your way. Let me tell you how.
How Volta manages Node
Volta allows you to install Node via the Volta CLI.
volta install node installs the latest LTS version of Node. You can also install a specific version with
volta install email@example.com for instance.
Whenever you run a Node program it will use the latest version you installed. If you need to use a specific version of Node for a project you can pin the currently active Node version to the project’s package.json with
volta pin node or a different Node version with
volta pin node@10 for instance.
From this point on all Node programs and locally installed npm packages that are being executed in this project are run on that pinned Node version and nothing else.
The pinning is nothing else besides an entry in the package.json. This means you can easily change the Node version by hand at any time if you want.
When you share this project via GitHub any other team member that has Volta installed on their machine will also automatically use the pinned Node version in that project. Volta will just go ahead and install it if you don’t have that specific version installed yet.
This is huge for teams. As long as Volta is installed everywhere it just takes care of using the right version per project and gets out of your way.
Many times I have experienced onboarding team members running into problems or experiencing inconsistencies because they were using a different Node version in a project.
How Volta manages package managers
Package managers can be installed and pinned per project with Volta.
On first install of a package manager Volta installs the latest stable Node version with it and binds the two so that the package manager works forever.
volta install trash-cli to use it.
Volta installs the latest LTS Node version with the tool if that version of Node was not installed yet and will always run the tool on that version of Node forever. No matter which version of Node you are using in your current project.
When you use a different Node version manager or install your Node versions globally yourself you can never be sure if all your CLI tools are working.
How it all works together
Once Node and package manager are pinned for a project and Volta is used by all devs on your team and your CI/CD automation, all weird bugs and weird behavior caused by incompatible Node and package manager versions are completely eliminated.
Meaning: if your setup worked once it will definitely work again later. No matter what you globally install for other projects.
It’s one of the first things I install on a fresh system. I highly recommend you have a good look at Volta.
And on top of everything it is wicked fast because it’s written in Rust and Rust compiles down to a native binary.