Skip to main content

nypm vs ni vs corepack: Package Manager Runners in Node.js (2026)

·PkgPulse Team

TL;DR

nypm is the UnJS universal package manager API — programmatic API to detect and run npm/yarn/pnpm/bun, auto-detects from lockfile, used by Nuxt CLI and other tools. ni is Anthony Fu's package manager runner — CLI that auto-detects your package manager and runs the right command (ninpm install or pnpm install or yarn), the most popular. corepack is Node.js's built-in package manager manager — ships with Node.js, enforces package manager versions via packageManager field, transparent proxying. In 2026: nypm for programmatic package manager abstraction, ni for interactive CLI use, corepack for version enforcement.

Key Takeaways

  • nypm: ~2M weekly downloads — UnJS, programmatic API, auto-detect, install/add/remove
  • ni: ~500K weekly downloads — Anthony Fu, CLI runner, auto-detect, aliased commands
  • corepack: ships with Node.js — version enforcement, transparent proxy, packageManager field
  • All three solve "which package manager does this project use?"
  • nypm is for tools/scripts; ni is for developers; corepack is for version pinning
  • ni has the best DX for daily development workflows

nypm

nypm — universal package manager API:

Detect package manager

import { detectPackageManager } from "nypm"

// Auto-detect from lockfile:
const pm = await detectPackageManager("/path/to/project")
console.log(pm)
// → { name: "pnpm", version: "9.0.0", command: "pnpm" }
// or { name: "npm", version: "10.0.0", command: "npm" }
// or { name: "yarn", version: "4.0.0", command: "yarn" }
// or { name: "bun", version: "1.0.0", command: "bun" }

// Detection priority:
// 1. pnpm-lock.yaml → pnpm
// 2. yarn.lock → yarn
// 3. package-lock.json → npm
// 4. bun.lockb → bun

Install dependencies

import { installDependencies, addDependency, removeDependency } from "nypm"

// Install all dependencies (like `npm install`):
await installDependencies({ cwd: "/path/to/project" })
// → Runs the right command: npm install, pnpm install, yarn, or bun install

// Add a dependency:
await addDependency("express", { cwd: "/path/to/project" })
// → pnpm add express (or npm install express, etc.)

// Add as dev dependency:
await addDependency("vitest", {
  cwd: "/path/to/project",
  dev: true,
})
// → pnpm add -D vitest

// Remove a dependency:
await removeDependency("lodash", { cwd: "/path/to/project" })
// → pnpm remove lodash

Advanced options

import { installDependencies, addDependency } from "nypm"

// Force a specific package manager:
await installDependencies({
  cwd: "/path/to/project",
  packageManager: "pnpm",
})

// Silent mode:
await addDependency("react", {
  cwd: "/path/to/project",
  silent: true,
})

// With workspace support:
await addDependency("shared-utils", {
  cwd: "/path/to/project",
  workspace: true,
})

How Nuxt uses nypm

// Nuxt CLI uses nypm to install modules:
// When you run: nuxi module add @nuxt/image

// Internally:
import { addDependency } from "nypm"

async function installModule(name: string) {
  // Auto-detects your package manager and runs the right command:
  await addDependency(name, {
    cwd: process.cwd(),
    dev: true,
  })
}

// Works regardless of whether the project uses npm, pnpm, yarn, or bun

ni

ni — CLI package manager runner:

Commands

# ni — install dependencies (like npm install):
ni
# → npm install / pnpm install / yarn / bun install

# ni <package> — add dependency (like npm install <pkg>):
ni express
# → npm install express / pnpm add express / yarn add express

# ni -D <package> — add dev dependency:
ni -D vitest
# → npm install -D vitest / pnpm add -D vitest

# nr — run script (like npm run):
nr dev
# → npm run dev / pnpm dev / yarn dev / bun run dev

# nr — interactive script selection:
nr
# → Shows list of scripts to choose from (fuzzy search)

# nun — uninstall (like npm uninstall):
nun lodash
# → npm uninstall lodash / pnpm remove lodash / yarn remove lodash

# nci — clean install (like npm ci):
nci
# → npm ci / pnpm install --frozen-lockfile / yarn install --frozen-lockfile

# nu — upgrade packages:
nu
# → npm update / pnpm update / yarn upgrade

Global install

# Install globally:
npm install -g @antfu/ni

# Or use with npx:
npx @antfu/ni

How detection works

ni detects your package manager by looking for lockfiles:

Priority:
  1. bun.lockb           → bun
  2. pnpm-lock.yaml      → pnpm
  3. yarn.lock            → yarn
  4. package-lock.json    → npm

Also checks:
  - packageManager field in package.json
  - Walks up directory tree to find lockfile

If no lockfile found:
  → Prompts you to choose a package manager

Configuration

# ~/.nirc — global config:
# Default package manager for new projects:
defaultAgent=pnpm

# Always use global agent for global installs:
globalAgent=npm

Real-world usage

# Clone any repo and just run:
git clone https://github.com/someone/project
cd project
ni        # Installs with the right package manager
nr dev    # Runs dev script with the right runner
nr build  # Runs build
nr test   # Runs tests

# No need to remember: is it npm/pnpm/yarn/bun?

corepack

corepack — Node.js built-in:

Enable corepack

# Corepack ships with Node.js but is disabled by default:
corepack enable

# Now pnpm and yarn are available as transparent proxies:
pnpm --version  # → Downloads and runs the correct version
yarn --version   # → Downloads and runs the correct version

Package manager field

// package.json — pin exact package manager version:
{
  "name": "pkgpulse",
  "packageManager": "pnpm@9.15.0"
}
# With corepack enabled:
pnpm install
# → Automatically uses pnpm@9.15.0
# → If wrong version installed, downloads the correct one

# If someone tries to use the wrong package manager:
npm install
# → Error: This project is configured to use pnpm

yarn install
# → Error: This project is configured to use pnpm

Version management

# Set package manager for project:
corepack use pnpm@9.15.0
# → Updates packageManager field in package.json

# Prepare (download for offline use):
corepack prepare pnpm@9.15.0 --activate

# Install specific version:
corepack install --global pnpm@9.15.0

CI/CD usage

# GitHub Actions:
name: Build
on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - run: corepack enable
      # Now pnpm/yarn uses the version from packageManager field
      - run: pnpm install --frozen-lockfile
      - run: pnpm build
      - run: pnpm test

How it works

corepack acts as a transparent proxy:

1. You run: pnpm install
2. corepack intercepts the command
3. Reads packageManager from package.json: "pnpm@9.15.0"
4. Downloads pnpm@9.15.0 if not cached
5. Forwards the command to pnpm@9.15.0

Benefits:
  ✅ Everyone uses the exact same version
  ✅ No global install conflicts
  ✅ CI and local environments are identical
  ✅ Automatic version management

Supported package managers:
  - pnpm
  - yarn (v1, v2+, v4+)
  - (npm is the default, not managed by corepack)

Feature Comparison

Featurenypmnicorepack
PurposeProgrammatic APICLI runnerVersion manager
Auto-detect PM✅ (lockfile)✅ (lockfile)✅ (packageManager field)
Install deps✅ (ni)N/A (proxies to PM)
Run scripts✅ (nr)N/A
Version pinning
Enforce PM
Interactive✅ (script selection)
Ships with Node
npm support❌ (npm is default)
bun support
Used byNuxt CLI, UnJS toolsDevelopersCI/CD, teams
Weekly downloads~2M~500KShips with Node

When to Use Each

Use nypm if:

  • Building tools that need to install packages programmatically
  • Need package manager detection in scripts/CLIs
  • Building a framework CLI (like Nuxt, Astro)
  • Want a universal API for npm/pnpm/yarn/bun

Use ni if:

  • Want the fastest workflow for daily development
  • Work across multiple projects with different package managers
  • Want interactive script selection (nr)
  • Tired of remembering pnpm add vs yarn add vs npm install

Use corepack if:

  • Need to pin package manager versions for a team
  • Want to enforce that everyone uses the same PM version
  • Need consistent CI/CD environments
  • Want zero-install package manager provisioning

Methodology

Download data from npm registry (weekly average, February 2026). Feature comparison based on nypm v0.3.x, @antfu/ni v0.21.x, and corepack (Node.js 22.x built-in).

Compare developer tooling and package management on PkgPulse →

Comments

Stay Updated

Get the latest package insights, npm trends, and tooling tips delivered to your inbox.