Glossary / yarn
Yarn
Yarn is a JavaScript package manager with multiple major generations and distinct installation models. Yarn Classic (1.x) commonly uses yarn.lock with a traditional node_modules tree; modern Yarn (Berry, 2+) adds Plug'n'Play as an option, workspace-focused tooling, constraints, and different configuration. A repository's Yarn generation must be identified before applying commands or advice.
Install models and workspaces
With nodeLinker: node-modules, Yarn creates a conventional installation tree. Plug'n'Play replaces broad node_modules resolution with a generated loader that maps declared dependencies explicitly, catching phantom dependencies and improving install determinism, though some tools need compatibility support. Yarn workspaces define multiple packages in one repository; the workspace: protocol expresses local package relationships and can affect published version ranges.
Yarn's lockfile and immutable-install command should be used consistently in CI. Modern Yarn uses yarn install --immutable; Classic commonly uses --frozen-lockfile. Do not copy flags across versions without checking. Modern Yarn also has package policies and configuration controlling install scripts, patches, and linker behavior.
Engineering guidance
Pin the Yarn release, for example with repository-managed version configuration, and document linker choice. Test editor, test runner, build, and release tooling under the chosen linker. Avoid mixing npm/pnpm/Yarn lockfiles. For workspace scripts, use commands that explicitly select packages and preserve dependency order where required.
Interview questions
- Why ask which Yarn version? Classic and modern Yarn differ in commands, configuration, workspace features, and linker model.
- What is Plug'n'Play? A generated dependency map/loader that avoids conventional
node_moduleslookup. - What does
workspace:indicate? A dependency should resolve to a local workspace package, with publish-time range behavior defined by Yarn. - How make CI installs immutable? Use the version-appropriate frozen/immutable install command.
- What migration risks exist? Tool compatibility, lifecycle scripts, resolution assumptions, and lockfile semantics.