volta run
The volta run
command will run the command that you give it, using versions of tools that are specified at the command line. It has the following syntax:
bash
Run a command with custom Node, npm, and/or Yarn versions
USAGE:
volta run [FLAGS] [OPTIONS] <command> [--] [args]...
FLAGS:
--bundled-npm Forces npm to be the version bundled with Node
--no-yarn Disables Yarn
--verbose Enables verbose diagnostics
--quiet Prevents unnecessary output
-h, --help Prints help information
OPTIONS:
--node <version> Set the custom Node version
--npm <version> Set the custom npm version
--yarn <version> Set the custom Yarn version
--env <NAME=value>... Set an environment variable (can be used multiple times)
ARGS:
<command> The command to run
<args>... Arguments to pass to the command
How It Works
Any tool that doesn't have a version specified directly will have its version determined by Volta's usual context detection, using the pinned versions in a project or the default versions.
Note The version settings must come before the command you wish to run. Anything after the command will be treated as arguments and will not be read by Volta.
Examples
Running with a Specific Node Version
bash
# Run npm test with Node 14
volta run --node 14 npm test
# Run a script with the latest Node 16
volta run --node 16 node script.js
Running with Custom Package Manager Versions
bash
# Run with a specific npm version
volta run --npm 7.10.0 npm install
# Run with a specific Yarn version
volta run --yarn 1.22.10 yarn add express
Combining Tool Versions
bash
# Run with specific Node and npm versions
volta run --node 14.17.0 --npm 6.14.13 npm install
# Run with Node 16 and Yarn 1.22.10
volta run --node 16 --yarn 1.22.10 yarn build
Using Bundled npm or Disabling Yarn
bash
# Force using the npm version bundled with Node
volta run --bundled-npm npm install
# Disable Yarn in the environment
volta run --no-yarn some-command
Setting Environment Variables
bash
# Set a single environment variable
volta run --env DEBUG=true npm test
# Set multiple environment variables
volta run --env NODE_ENV=production --env DEBUG=false node server.js
Use Cases
The volta run
command is useful for:
- Testing with Different Versions: Test your code against different Node.js versions without changing your default or project settings
- One-off Tasks: Run commands with specific tool versions for specialized tasks
- CI/CD Environments: Use in continuous integration pipelines to test against multiple Node.js versions
- Dependency Installation: Install dependencies with a specific version of npm or Yarn
- Temporary Environment Changes: Run commands with modified environment variables without affecting your global setup
Common Patterns
Testing Across Multiple Node Versions
bash
# Test with Node 14
volta run --node 14 npm test
# Test with Node 16
volta run --node 16 npm test
# Test with Node 18
volta run --node 18 npm test
Running NPX Commands with Specific Versions
bash
# Run create-react-app with a specific Node version
volta run --node 16 npx create-react-app my-app
# Execute TypeScript compiler with a specific Node version
volta run --node 14 npx tsc
Script Execution
bash
# Run a build script with a specific environment
volta run --env NODE_ENV=production node build.js