yarn
π―SkillInstallation
npx skills add g1joshi/agent-skills --skill yarnRun it in a terminal; it asks which AI coding tools to install it for (Claude Code, Codex, Cursor and more).
Uses skills.sh Β· Node.js 22.20+
After installing
Ask for related work and the agent uses it on its own, or call it yourself.
/yarnInstall by hand
Copy the whole skill folder from GitHub to the place below. Copying only SKILL.md can leave out files the skill uses.
Open the skill folder β- This project
.claude/skills/yarn/ - All projects
~/.claude/skills/yarn/
These paths are for Claude Code. For other tools, the command above puts it in the right place.
SKILL.md
View on GitHub βExpert Yarn package manager assistance covering Yarn Berry (v4+), Zero-Installs, PnP (Plug'n'Play), and workspaces. Use when managing fast, deterministic JavaScript monorepo dependencies.
Yarn
Yarn (Berry) is a modern package manager. It introduced Plug'n'Play (PnP) to eliminate node_modules and support Zero Installs.
When to Use
- Modern JavaScript Package Management (Yarn v4+): Fast, reliable dependency management with Corepack support.
- Plug'n'Play (PnP) & Zero-Installs: Eliminating
node_modulesfolders for instant workspace switching and CI runs. - Enterprise Monorepos: Coordinated workspace resolution, constraints, and release workflows.
- Hardened Security & Integrity: Strict lockfile checksums and automated dependency audits.
Quick Start
corepack enable
yarn set version stable
yarn init -2
# Install
yarn add react
Core Concepts
Modern Yarn Configuration (.yarnrc.yml)
Configuring node-modules linker or Plug'n'Play:
# .yarnrc.yml
nodeLinker: node-modules # Use 'pnp' for Zero-Installs, 'node-modules' for standard compatibility
compressionLevel: mixed
enableGlobalCache: true
packageExtensions:
"@types/react@*":
peerDependencies:
react: "*"
Workspace Commands in Monorepos
Executing commands across workspaces:
# Run build command in parallel across all workspaces
yarn workspaces foreach --parallel --verbose run build
# Run tests only on workspaces changed relative to main branch
yarn workspaces foreach --since=main run test
# Add dependency to a specific workspace
yarn workspace @my-org/web-app add swr
Upgrading Dependencies with Interactive CLI
Upgrading packages adhering to SemVer:
# Interactively review and upgrade outdated packages
yarn upgrade-interactive
# Re-validate lockfile integrity
yarn install --immutable
Common Patterns
Yarn Berry Monorepo Workspaces with TypeScript Loose Mode
Problem: Slow installs and node_modules bloat across multiple internal monorepo packages.
Solution:
Configure Yarn Berry workspaces with .yarnrc.yml:
# .yarnrc.yml
nodeLinker: node-modules # Use node-modules linker for maximum ecosystem compatibility
yarnPath: .yarn/releases/yarn-4.5.0.cjs
packageExtensions:
"react-scripts@*":
dependencies:
"typescript": "*"
Root package.json:
{
"private": true,
"workspaces": ["apps/*", "packages/*"]
}
Best Practices
Do:
- Target modern Yarn (v4+) enabled through Corepack (
corepack enable yarn). - Use
yarn install --immutablein CI/CD pipelines to prevent unintended lockfile updates. - Leverage
yarn workspaces foreachwith--since=mainto test only modified packages in monorepos. - Use
packageExtensionsin.yarnrc.ymlto cleanly resolve missing peer dependency warnings from older third-party packages.
Don't:
- Use legacy Yarn 1.x (Classic); migrate to modern Yarn v4+ for enhanced performance and security.
- Edit
yarn.lockmanually; resolve conflicts viayarn install. - Mix npm or pnpm lockfiles within a Yarn repository.
Troubleshooting
| Error | Cause | Solution |
|---|---|---|
Usage Error: Couldn't find the node_modules state file | Project running under PnP mode when tools expect node_modules. | Set nodeLinker: node-modules in .yarnrc.yml and run yarn install. |
YN0002: Missing peer dependency | Package requires peer dependency not declared in consumer. | Declare missing package in root .yarnrc.yml packageExtensions. |
Yarn command not found | Yarn Berry binary missing in .yarn/releases/. | Run corepack enable && corepack use yarn@stable. |
References
More from this repository10
A template skill providing a starter framework for creating new agent skills with structured sections for triggers, quick start examples, and capability descriptions.
Skill
Skill
Skill
Skill
Skill
Skill
Skill
Skill
Skill