Yarn Frequently Asked Questions
Version-Related Questions
Why is the yarn package on npm still on 1.x?
Yarn Modern releases haven't been distributed on npm since 2019. The reason is that many people relied on npm install -g yarn as part of their image building, and any breaking change would break their deployments.
As a result, the Yarn team decided to retire the yarn npm package and only use it for 1.x maintenance releases. Modern Yarn is now installed directly from the website via Corepack or yarn set version.
Why should you upgrade to Yarn Modern?
While Yarn Classic (1.x) remains important in the JavaScript ecosystem, upgrading is recommended when possible:
- New Features: Beyond classic features, Modern offers plugins extending functionality like changesets, constraints, workspaces, etc.
- Efficiency: New install strategies significantly reduce project size (e.g., CRA artifacts reduced from 237MB to 45MB)
- Extensibility: Build your own features according to your specifications without waiting for official implementation
- Stability: Fixes longstanding design issues from Classic
- Future-proof: Modern architecture allows faster feature development
How difficult is migration from Classic to Modern?
Generally, a few main issues need to be addressed:
- Configuration Format Change: No longer reads
.npmrcor.yarnrc, uses.yarnrc.ymlinstead - Third-party Package Dependencies: Some packages don't list dependencies properly, requiring
packageExtensionsfixes - Editor Support: Requires one-time SDK setup
- Tool Compatibility: Tools like React Native and Flow may need
node_moduleslinker strategy
Most projects can complete migration in half a day of work.
Usage Questions
Which files should be gitignored?
When using Zero-Installs:
.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
When not using Zero-Installs:
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
File Explanations:
.yarn/cacheand.pnp.*: Can be safely ignored, but requireyarn installafter branch switching.yarn/patches: Contains patch files, must be committed to repository.yarn/pluginsand.yarn/releases: Contains Yarn releases, recommended to commit for team consistencyyarn.lock: Should always be committed to repository
Does Yarn support ESM?
Yes, Yarn supports ESM.
Yarn supports the node-modules install strategy, identical to npm installation. For PnP (Plug'n'Play) mode, ESM support has been available since version 3.1 through Node Loaders.
Should lockfiles be committed to the repository?
Yes, always commit them.
Regardless of whether you're developing standalone applications or distributed libraries, lockfiles should be stored with project source code. This ensures:
- Consistent developer experience for all contributors
- Project remains buildable in the future
- Avoids dependency version drift issues
Continuous integration testing should be handled by CI systems, not by omitting lockfiles.
Technical Architecture Questions
Is Yarn operated by Facebook?
No. While Yarn was initially implemented by a Facebook employee, the current active development team consists entirely of employees from non-founding companies. Facebook employee contributions go through the same review process as other contributors.
What is registry.yarnpkg.com? Does Facebook track us?
registry.yarnpkg.com is just a CNAME record pointing to the npm registry, with no backend server. The Yarn team maintains this hostname for reliability—if the primary source becomes unavailable, it can redirect to a read-only registry copy.
Yarn collects basic client-side telemetry, but no HTTP logs reach Yarn project infrastructure, let alone Facebook.
Is Yarn faster than other package managers?
Performance is relative and temporary. Yarn's main differences lie in priorities and core values:
- Prioritizes workspace functionality because monorepos provide significant value
- Invests heavily in Plug'n'Play because it's important for the ecosystem
- Makes autonomous decisions based on project roadmap
Why is TypeScript patched even if I don't use Plug'n'Play?
Yarn automatically applies TypeScript PnP support patches to downloaded TypeScript versions because:
- Consistency: Ensures consistent behavior between development (node_modules) and production (PnP) environments
- Cache Consistency: Prevents package cache differences that could break immutable installs
- Harmless: The patch is a no-op if PnP isn't enabled
- Community Contribution: Hopes to eventually merge this PR into TypeScript main branch
Best Practices
Script Sharing
Script names containing colons (e.g., build:foo) can be called from any workspace. Combined with the $INIT_CWD environment variable, this enables reusable scripts:
{
"scripts": {
"g:tsc": "cd $INIT_CWD && tsc"
}
}
Then call from any workspace containing tsconfig.json:
{
"scripts": {
"build": "yarn g:tsc"
}
}
Note: This document is based on official content from the yarnpkg.com QA page, covering common questions and best practices for all versions.
