Manifest (package.json)
Reference for all supported package.json fields in Yarn projects.
Manifest (package.json)
Allowed fields in package.json files
Manifest files (also called package.json because of their name) contain everything needed to describe the settings unique to one particular package. Project will contain multiple such manifests if they use the workspace feature, as each workspace is described through its own manifest.
Name of the package.
Used to identify it across the application, especially amongst multiple workspaces. The first part of the name (here @scope/) is optional and is used as a namespace).
Version of the package.
Usually doesn't have any impact on your project, except when it is a workspace - then its version must match the specified ranges for the workspace to be selected as resolution candidate.
Stable version used as the base for deferred version bumps.
When present, Yarn will use this value instead of version as the current stable release when applying deferred version changes. This is useful for prerelease workflows where version may already include a prerelease suffix.
# Keep deferred versioning based on the last stable release.
stableVersion: "2.4.0"
# Record a stable baseline while the package version is a prerelease.
stableVersion: "3.0.0"
Define the package manager that should be used when working on this project.
This field is used by Corepack and similar tools to detect the Yarn version in use in a project - in a sense, it has the same purpose as your lockfile, but only for Yarn itself.
Yarn will automatically set this value when running yarn set version.
# Pin a project to Yarn 6.
packageManager: "yarn@6.0.0"
# Use a local Yarn Switch binary while developing it.
packageManager: "yarn@local:../zpm-switch/target/release/yarn"
Define the package manager that should be used while migration mode is enabled.
This field is used by Yarn Switch when migration mode is active. It lets a project temporarily opt into a different Yarn binary without replacing the regular packageManager field.
# Test a newer Yarn release while keeping the regular package manager unchanged.
packageManagerMigration: "yarn@6.0.0"
# Point migration mode at a local Yarn Switch build.
packageManagerMigration: "yarn@local:../zpm-switch/target/release/yarn"
Define how should be interpreted .js files.
A Node.js v13.x option. Possible values are commonjs (the default) and module. Yarn 3+ will generate a .pnp.cjs file when using PnP regardless of this option.
Workspace profile names to apply to this workspace.
Each listed profile is resolved from the workspaceProfiles yarnrc setting. Profiles can contribute development dependencies to the workspace, and a default profile is applied automatically when it exists.
# Apply a single TypeScript tooling profile.
extends:
- "typescript"
# Compose multiple workspace profiles.
extends:
- "tooling"
- "web"
Define whether the package is meant to be published.
If true, the package is considered private and Yarn will refuse to publish it regardless of the circumstances.
SPDX identifier defining the license under which the package is distributed.
Set of platforms on which this package works.
The value of process.platform() will be compared at install-time against this set. Should no matches be found, any postinstall script the package define will be skipped. If the package was exclusively depended upon via optionalDependencies entries, the package won't be installed at all.
# Allow installs on Linux and macOS.
os:
- "linux"
- "darwin"
# Exclude Windows by using the npm negation syntax.
os:
- "!win32"
Set of CPU architectures on which this package works.
The value of process.arch() will be compared at install-time against this set. Should no matches be found, any postinstall script the package define will be skipped. If the package was exclusively depended upon via optionalDependencies entries, the package won't be installed at all.
# Allow x64 and arm64 installs.
cpu:
- "x64"
- "arm64"
# Exclude 32-bit x86 installs.
cpu:
- "!ia32"
Set of C standard libraries on which this package depends.
The host standard library will be compared at install-time against this set. Should no matches be found, any postinstall script the package define will be skipped. If the package was exclusively depended upon via optionalDependencies entries, the package won't be installed at all.
# Install only on glibc-based Linux distributions.
libc:
- "glibc"
# Allow both common Linux C libraries.
libc:
- "glibc"
- "musl"
Path of the file that should be resolved when requiring the package via a bare identifier.
This field can be modified at publish-time through the use of the publishConfig.main field.
Entry points exported by the package.
Defines which package paths can be imported by consumers. It can be a single path, a conditional map, an array of fallbacks, or null for disabled entries.
# Export a single CommonJS entry point.
exports: "./dist/index.js"
# Export separate ESM and CommonJS builds.
exports:
".":
import: "./dist/index.mjs"
require: "./dist/index.cjs"
"./package.json": "./package.json"
Private package import aliases.
Defines #-prefixed import specifiers that can be used from within this package.
# Map one private alias to a local file.
imports:
"#internal": "./sources/internal.js"
# Use conditional imports for runtime-specific files.
imports:
"#runtime":
node: "./sources/runtime-node.js"
default: "./sources/runtime-browser.js"
Path of the file that should be resolved when requiring the package via a bare identifier in an ES6-compatible bundler environment.
This field should be considered deprecated, with exports being its official replacement.
Browser-specific entry point or path replacements.
Bundlers may use this field to replace Node-oriented files with browser-compatible alternatives, or to ignore files by mapping them to false.
# Point bundlers at a browser-specific build.
browser: "./dist/browser.js"
# Replace or disable individual files for browser builds.
browser:
"./sources/node.js": "./sources/browser.js"
fs: false
Arbitrary value selecting the linker to use when installing the dependency.
This is an internal package setting that shouldn't be touched unless you really know what you're doing.
Set of files to expose via yarn run bin-name and the shell environment.
If set to a string, the binary value will be the package name (not including its scope part).
# Expose one binary named after the package.
bin: "./dist/cli.js"
# Expose multiple named binaries.
bin:
my-bin: "./dist/my-bin.js"
my-helper: "./dist/helper.js"
Set of scripts to expose via yarn run script-name, or as lifecycle hooks.
Scripts in Yarn are executed by a POSIX-like shell which implements most features you would want to use in one-liner scripts. For example you can assign environment variables using the POSIX syntax, and Yarn will make it work across both Linux, OSX, and Windows.
# Define common project scripts.
scripts:
build: "tsc -b"
test: "vitest run"
# Use Yarn's portable shell features in a script.
scripts:
count-words: "echo \"$@\" | wc -w"
Set of dependencies that must be made available to the current package in order for it to work properly.
Consult the protocol documentation for more information.
# Depend on a registry package.
dependencies:
webpack: "^5.0.0"
# Depend on a sibling workspace.
dependencies:
"@acme/utils": "workspace:^"
Set of dependencies that Yarn should only try to install if the os/cpu/libc fields match those of the host platform.
Unlike regular dependencies, those listed in optionalDependencies are allowed to have a failing postinstall step - in fact, they won't even be installed at all if the os/cpu/libc filters don't cover the host platform.
Note that optionalDependencies only cares about whether the package should install/build or not - it should still be resolvable, as otherwise it's impossible to tell whether a failure to retrieve the package metadata is intentional or not.
# Install a platform-specific dependency when supported.
optionalDependencies:
fsevents: "^2.3.0"
# Keep an optional native helper from failing the whole install.
optionalDependencies:
"@acme/native-helper": "^1.0.0"
Set of dependencies that must be made available to the current package in order for it to work properly as a workspace.
Unlike regular dependencies, those listed in devDependencies will only be required when the package is installed as part of a workspace project - usually by cloning the project repository then running yarn install inside it.
# Add build tooling used by this workspace.
devDependencies:
typescript: "^5.0.0"
vite: "^6.0.0"
# Use a package supplied by a workspace profile unless overridden locally.
devDependencies:
eslint: "^9.0.0"
Set of dependencies that the package must inherit from its ancestor in the dependency tree.
The semantic of peer dependencies guarantee that when the package require the dependency, it will be returned the exact same object instance as the one that would be returned to the package's ancestor. This mechanism makes peer dependencies the best way to share singleton states across multiple packages.
As an extension, Yarn supports "peer dependencies with default": dependencies listed in both the dependencies and a peerDependencies fields will try to solve the peer dependency first, but will fallback to the regular dependency if it can't be satisfied otherwise.
# Require consumers to provide React.
peerDependencies:
react: "^19.0.0"
react-dom: "^19.0.0"
# Accept any compatible bundler-provided webpack instance.
peerDependencies:
webpack: "*"
Folder glob patterns referencing the workspaces of the project.
Workspaces are an optional feature used by monorepos to split a large project into semi-independent subprojects, each one listing their own set of dependencies. The workspaces field is usually a list of glob patterns that match all directories that should become workspaces of your application. Consult the workspaces documentation for more information.
# Declare every package under a packages folder as a workspace.
workspaces:
- "packages/*"
# Use the legacy object form with an explicit packages list.
workspaces:
packages:
- "packages/*"
- "tools/*"
Workspace package globs.
Deprecated workspace globs that should not be hoisted.
This legacy field is accepted so Yarn can warn about it, but it isn't honored.
Extra settings affecting how the dependencies and devDependencies fields are interpreted.
In the context of a workspaced project most of these settings will affect all workspaces and as such must be specified at the root of the project. Unless noted otherwise, the dependenciesMeta field will be ignored if found within a workspace.
# Disable builds for a package that should never run postinstall scripts.
dependenciesMeta:
fsevents:
built: false
# Force a package to be unplugged on disk.
dependenciesMeta:
nan:
unplugged: true
Define whether to run the postinstall script or not.
If false, the package will never be built (deny-list). This behavior is reversed when the enableScripts yarnrc setting is toggled off - when that happens, only packages with built explicitly set to true will be built (allow-list); as for those with built explicitly set to false, they will simply see their build script warnings downgraded into simple notices.
Define whether the package must be unplugged or not.
If true, the specified package will be automatically unplugged at install time. This should only be needed for packages that contain scripts in other languages than Javascript (for example nan contains C++ headers).
Extra settings affecting how the peerDependencies field is interpreted.
Unlike dependenciesMeta, peerDependenciesMeta is allowed in any parts of the dependency tree.
# Mark a peer dependency as optional.
peerDependenciesMeta:
react-dom:
optional: true
# Silence warnings for an integration peer that is only needed in some environments.
peerDependenciesMeta:
webpack:
optional: true
Define whether to log a warning when the peer dependency can't be satisfied.
If true, the selected peer dependency will be marked as optional by the package manager, silencing any warning we would otherwise emit.
Override the resolutions of specific dependencies.
This field allows you to instruct Yarn to use a specific resolution (specific package version) instead of anything the resolver would normally pick. This is useful to enforce all your packages to use a single version of a dependency, or backport a fix. The syntax for the resolution key accepts one level of specificity, so all the following examples are correct.
Note: When a path is relative, like it can be with the file: and portal: protocols, it is resolved relative to the path of the project.
Note: The resolutions field can only be set at the root of the project, and will generate a warning if used in any other workspace.
# Force all consumers of a package to use one version.
resolutions:
relay-compiler: "3.0.0"
# Override a transitive dependency below a specific package.
resolutions:
"@babel/core/@babel/generator": "7.3.4"
Define whether the package must be unplugged or not.
While Yarn attempts to reference and load packages directly from their zip archives, it may not always be possible. A heuristic tries to detect cases where zip-loading would be problematic and unpack the files on disk instead but, being just a heuristic, it may report incorrect results.
The preferUnplugged field lets you define yourself, as a package author, whether your package works or not when stored as an archive. If set, it will override the default heuristic.
Array of file glob patterns that will be included within the published tarball.
File patterns follow a similar syntax to .gitignore, but reversed: including a file, directory, or glob pattern (*, **/*, and such) will make it so that file is included in the tarball when it’s packed. Omitting the field will make it default to ["*"], which means it will include all files.
If this field is missing, Yarn will use the project's .gitignore to generate the pack list, or the .npmignore file instead if available.
Some special files and directories are also included or excluded regardless of whether they exist in the files array.
# Publish only compiled output and package metadata.
files:
- "dist/**/*"
- "package.json"
- "README.md"
# Include source files alongside generated types.
files:
- "sources/**/*"
- "dist/**/*.d.ts"
Extra settings affecting how the package is published.
# Publish compiled files instead of source entry points.
publishConfig:
main: "./build/index.js"
module: "./build/index.mjs"
types: "./build/index.d.ts"
# Publish with provenance and a package-specific export map.
publishConfig:
provenance: true
exports:
".":
import: "./build/index.mjs"
require: "./build/index.cjs"
Define the access to use when publishing the package.
Valid values are public and restricted, but restricted usually requires to register for a paid plan (this is up to the registry you use).
Replacement of the package's bin field, used in the published tarball over the main one.
Replacement of the package's browser field, used in the published tarball over the main one.
Set of files that must be marked as executable (+x) in the published tarball.
Replacement of the package's exports field, used in the published tarball over the main one.
Replacement of the package's imports field, used in the published tarball over the main one.
Replacement of the package's main field, used in the published tarball over the main one.
Replacement of the package's module field, used in the published tarball over the main one.
Define whether to produce a provenance statement for the package when publishing. Overrides all other provenance settings.
If present, will replace whatever registry is defined in the configuration when the package is about to be pushed to a remote location.
Replacement of the package's type field, used in the published tarball over the main one.
Replacement of the package's types field, used in the published tarball over the main one.
Replacement of the package's typings field, used in the published tarball over the main one.
Extra settings affecting how the package is installed.
# Prevent dependencies from being hoisted past each workspace.
installConfig:
hoistingLimits: "workspaces"
# Disable self-referencing symlinks for this workspace.
installConfig:
selfReferences: false
Defines the highest point where packages can be hoisted.
See nmHoistingLimits for more information.
Defines whether workspaces are allowed to require themselves.
See nmSelfReferences for more information.