C.W.K.
Stream
Lesson 03 of 05 · published

Daily Yarn Berry Commands

~11 min · yarn, commands, workflow

Level 0Newbie
0 XP0/55 lessons0/16 achievements
0/80 XP to next level80 XP to go0% complete

Berry's CLI is similar to npm/pnpm but with intentional renamings. Memorize the small differences and the muscle memory transfers.

yarn add <pkg> adds a runtime dep. yarn add --dev <pkg> (note: --dev, not -D) adds a dev dep. yarn remove <pkg> removes one. yarn install installs everything; yarn install --immutable is Berry's npm ci equivalent — strict, CI-friendly, fails if the lockfile would change.

yarn up <pkg> upgrades a package (Berry-specific verb; npm/pnpm use upgrade). yarn upgrade-interactive opens a TUI to pick which packages to bump.

yarn dlx <tool> runs a tool without installing — Berry's npx. yarn workspaces foreach run build runs a script across every workspace package; yarn workspaces list enumerates them.

yarn node script.js runs Node with PnP runtime injected — necessary because PnP code can't run under plain node without setup. (If you use nodeLinker: node-modules in .yarnrc.yml to disable PnP, plain node works fine.)

Code

Daily Berry commands·bash
# Add / remove
yarn add express
yarn add --dev vitest typescript
yarn remove express

# Install
yarn install
yarn install --immutable    # CI mode (npm ci equivalent)

# Run scripts
yarn build
yarn test
yarn dev

# Run a tool without installing
yarn dlx create-vite my-app

# Upgrade interactively
yarn upgrade-interactive
Workspaces — first-class monorepo·bash
# In a Berry monorepo (workspaces declared in package.json)
yarn workspaces list

# Run 'build' in every workspace
yarn workspaces foreach run build

# Run 'dev' only in the 'web' workspace
yarn workspace web run dev

# Add a dep to a specific workspace
yarn workspace web add react

External links

Exercise

In a Berry project, run 'yarn dlx create-vite my-app'. Then 'cd my-app && yarn install --immutable'. Inspect the resulting .yarn/ directory — see the cache, the releases, the unplugged folder if PnP is on. Each piece exists for a reason; the docs explain each.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.