News and Updates
Global installs done right
So why do folks avoid global installs in the first place?
- Relying on global tools can make your project depend on something that isn’t listed in its
devDependencies, making it harder for other developers to contribute.
- Other developers could have different versions of the same global tools, leading to hard-to-identify bugs or inconsistencies in behavior.
- Unrelated projects on your own machine might depend on different versions of a tool, meaning you now have to manage those versions and switch between them when switching projects.
Some experts advocate including any tools your project depends on in your dependencies and then using the
scripts hash in package.json to facilitate running those tools. This way any developer using your code will be able to easily run the same versions of the same tools that you do. This solution, while powerful, is not without its own issues:
- Requires the mental overhead of knowing what script to run to invoke a given tool (
- Can make it tricky to customize the command, for example to run a single test from a test suite.
- Doesn’t work for tools that are used to bootstrap projects, like
Volta solves both of these sets of problems by providing smart proxies for any and all of your JS tools.
- By running
volta install mocha, you let Volta know that you want
mochato be available everywhere in your terminal. Volta will download the latest version (or if you want you can specify a specific version) to use as the default.
- From that point forward, you’ll be able to run that default version of
mochadirectly in your terminal, just as if you had globally installed it with npm.
- However, if you run
mochain a project that has the
mochapackage as a dependency, Volta will automatically delegate to the local version installed in
node_modules, without you having to change the command at all.
This proxy behavior lets you get all the usefulness of having tools directly available in your terminal, without having to worry about switching versions when switching projects. As a bonus, Volta will also pin a version of Node when installing each tool, so you don’t have to worry about having to re-install the tools if you update your default version of Node—they will all continue to work!