DEV Community

Yousuf Khan Ratul
Yousuf Khan Ratul

Posted on

Moving to pnpm and Volta: Enhancing Your Frontend Development Workflow

When it comes to JavaScript/TypeScript development, selecting the appropriate tools can greatly influence your productivity and project management. Are you using npm and nvm/fnm? You might not realize that there's a faster, more efficient way to develop. Here are two powerful tools, pnpm and Volta, that can boost your development workflow without any drawbacks.

The Current State: npm and nvm/fnm

If you're like most JavaScript developers, you're probably using:

  • npm for package management
  • nvm or fnm for Node.js version management

These tools have served us well, but they come with some hidden costs:

  • Sluggish package installations eating into your coding time
  • Massive node_modules folders clogging up your hard drive
  • The "works on my machine" syndrome due to inconsistent Node.js versions
  • Onboarding friction for new team members

pnpm: The Package Manager You Wish You Knew About Sooner

Think of pnpm as npm's faster, smarter cousin. It does everything npm does, but better:

  • Lightning-fast installations: pnpm is up to 2x faster than npm
  • 💾 Tiny disk footprint: Say goodbye to duplicate dependencies
  • 🔒 Bulletproof dependency management: No more phantom dependencies
  • 📦 Built for modern development: First-class monorepo support

A real-world example from the Vue.js repository source: pnpm benchmarks, 2023:

# Before (npm):
Time: 1m 22s
Disk space: 1.3GB

# After (pnpm):
Time: 41s
Disk space: 390MB
Enter fullscreen mode Exit fullscreen mode

Additional benchmarks from the Next.js repository source: pnpm documentation:

Package Manager Installation Time Disk Space
npm 75 seconds 910MB
yarn 68 seconds 899MB
pnpm 33 seconds 333MB

Volta: The Node.js Version Manager That Just Works

Volta is what nvm wants to be when it grows up:

  • 🔄 Automatic project-specific tooling: The right Node.js version, every time
  • 🔨 Beyond Node.js: Manages ALL your JavaScript tools
  • Blazing fast: Built in Rust for instant switching
  • 🖥️ Actually cross-platform: Works flawlessly on Windows too

Making the Switch: Easier Than You Think

Install Your New Tools

npm install -g pnpm

curl https://get.volta.sh | bash

winget install Volta.Volta
Enter fullscreen mode Exit fullscreen mode

Convert Your Existing Project to pnpm

pnpm import

rm -rf node_modules
pnpm install
Enter fullscreen mode Exit fullscreen mode

Set Up Volta Correctly

Ensuring Volta Manages Your Path

# For Bash
echo 'export VOLTA_HOME="$HOME/.volta"' >> ~/.bashrc
echo 'export PATH="$VOLTA_HOME/bin:$PATH"' >> ~/.bashrc

# For Zsh
echo 'export VOLTA_HOME="$HOME/.volta"' >> ~/.zshrc
echo 'export PATH="$VOLTA_HOME/bin:$PATH"' >> ~/.zshrc

source ~/.bashrc  # or source ~/.zshrc

# For Fish
set -Ux VOLTA_HOME "$HOME/.volta"
fish_add_path "$VOLTA_HOME/bin"

# For PowerShell
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
$voltaPath = "$env:USERPROFILE\.volta\bin"
if ($userPath -notlike "*$voltaPath*") {
    [Environment]::SetEnvironmentVariable("PATH", "$voltaPath;$userPath", "User")
}

[Environment]::SetEnvironmentVariable("VOLTA_HOME", "$env:USERPROFILE\.volta", "User")
Enter fullscreen mode Exit fullscreen mode

Verifying Your Setup

which node  # Unix-like systems
where.exe node  # Windows

volta list  
Enter fullscreen mode Exit fullscreen mode

Everyday Command Comparisons

1. Installing Node.js Versions

# nvm
nvm install 16
nvm install 14

# Volta
volta install node@16
volta install node@14
Enter fullscreen mode Exit fullscreen mode

2. Switching Global Node.js Version

# nvm
nvm use 16

# Volta
volta install node@16
Enter fullscreen mode Exit fullscreen mode

3. Setting Project-Specific Node.js Version

# nvm
echo "16" > .nvmrc
nvm use  

# Volta
volta pin node@16  
Enter fullscreen mode Exit fullscreen mode

4. Installing and Using Tools

# npm
npm install -g yarn

# Volta
volta install yarn
Enter fullscreen mode Exit fullscreen mode

Real-World Example: Managing Multiple Projects

volta install node@18  

cd ~/projects/nextjs-app
volta pin node@18
volta pin npm@9
volta pin yarn@1.22

cd ~/projects/legacy-app
volta pin node@14
volta pin npm@6

cd ~/projects/nextjs-app  # Node.js 18 and npm 9 automatically activated
cd ~/projects/legacy-app  # Node.js 14 and npm 6 automatically activated
Enter fullscreen mode Exit fullscreen mode

"But What About…" — Addressing Common Concerns

"Will this break my existing projects?"

Nope! pnpm is 100% compatible with npm. Your package.json remains the same, and you can even keep package-lock.json as a backup.

"Is it worth the hassle of switching?"

The migration takes minutes, and the benefits are immediate: faster installs, less disk space, and consistent environments across your team.

"What if I need to switch back?"

No problem! Your npm knowledge isn't wasted — pnpm uses similar commands:

npm install   →   pnpm install  
npm run dev   →   pnpm dev  
npm test      →   pnpm test
Enter fullscreen mode Exit fullscreen mode

The Day-to-Day Difference

Before:

nvm use 14  
npm install 
cd another-project  
nvm use 16  
npm install 
Enter fullscreen mode Exit fullscreen mode

After:

cd project-1  
pnpm install  
cd project-2  
pnpm install  
Enter fullscreen mode Exit fullscreen mode

Troubleshooting Common Issues

PATH Issues

If you're still seeing the system Node.js or nvm-managed Node.js:

Check your PATH order:

echo $PATH  # Unix-like systems
$env:Path   # Windows PowerShell
Enter fullscreen mode Exit fullscreen mode

Common issues and fixes:

Issue Solution
System Node.js still active Ensure Volta's bin directory is first in PATH
nvm interfering Remove nvm initialization from shell config
Wrong version showing Run volta install node@desired-version

Complete Migration Guide: From npm/nvm to pnpm/Volta

Project Migration

cd your-project-directory

volta pin node@$(node -v)

pnpm import  

rm -rf node_modules package-lock.json

pnpm install
Enter fullscreen mode Exit fullscreen mode

Update Scripts

{
  "scripts": {
    "start": "pnpm run start",
    "test": "pnpm run test",
    "build": "pnpm run build"
  }
}
Enter fullscreen mode Exit fullscreen mode

Update CI/CD Pipeline

name: CI
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: volta-cli/action@v1
      - uses: pnpm/action-setup@v2
        with:
          version: 8
      - name: Install dependencies
        run: pnpm install --frozen-lockfile
      - name: Run tests
        run: pnpm test
Enter fullscreen mode Exit fullscreen mode

Transition Period Workflow

During team transition, you might need to maintain compatibility:

# If someone runs npm install, sync with pnpm
npm install
pnpm import
pnpm install

# Commit both lock files during transition
git add package-lock.json pnpm-lock.yaml
Enter fullscreen mode Exit fullscreen mode

Common Issues & Solutions

Missing Packages After Migration

# Check for and add missing peer dependencies
pnpm install 
Enter fullscreen mode Exit fullscreen mode

Global Packages Missing

volta install package-name
Enter fullscreen mode Exit fullscreen mode

Script Running Issues

pnpm rebuild
Enter fullscreen mode Exit fullscreen mode

Migration Verification Checklist

  • volta list shows the correct Node.js version
  • pnpm install runs successfully
  • All scripts in package.json work
  • CI/CD pipeline passes
  • The development server starts correctly
  • Tests pass with pnpm
  • The build process completes successfully

Rollback Plan (If Needed)

rm -rf node_modules pnpm-lock.yaml
npm install

rm package.json.volta

nvm use $(cat .nvmrc)
Enter fullscreen mode Exit fullscreen mode

Ready to Upgrade Your Developer Experience?

Making the switch to pnpm and Volta is all upside:

  • ✅ Faster installations
  • ✅ Less disk space usage
  • ✅ Automatic tool management
  • ✅ Better dependency handling
  • ✅ Full compatibility with existing projects

Ready to get started? Once you make the switch, you'll question why you didn't do it earlier — trust me.

Top comments (0)