Manifest (package.json)
Reference for all supported package.json fields in Yarn projects.
Manifest (package.json)
Allowed fields in package.json files
JSON schema for editor validation and autocompletion.
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. Fields whose types include null accept it as an unset value. Dependency maps, script maps, workspace lists, and publishConfig must retain their documented collection or object types. Nested exports targets may be null to block an export; nested imports targets must be strings or objects.
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).
# Example
name: "@scope/name"
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.
# Example
version: "1.2.3"
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.
# Example
type: "module"
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.
# Example
private: true
SPDX identifier defining the license under which the package is distributed.
Yarn doesn't interpret this field; it's published along with the rest of the manifest for registries and other tools to consume. License files (LICENSE, LICENCE, and their variants) are always included in the published tarball, regardless of files.
# Distribute the package under the MIT license.
license: "MIT"
# Let consumers pick between two licenses.
license: "(MIT OR Apache-2.0)"
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.
As with os and cpu, values prefixed with ! are excluded, and a list mixing both forms only accepts the values it lists that aren't also excluded. Hosts without a detected standard library (macOS, Windows) never match a libc set, even a negated one.
# Install only on glibc-based Linux distributions.
libc:
- "glibc"
# Allow both common Linux C libraries.
libc:
- "glibc"
- "musl"
# Exclude musl-based Linux distributions.
libc:
- "!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.
# Example
main: "./sources/index.js"
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.
# Example
module: "./sources/index.mjs"
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.
Accepted for compatibility with earlier Yarn versions, but not currently read by Yarn.
# Example
languageName: "node"
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.
Folder glob patterns referencing the workspaces of the project, used when workspaces is written in its legacy object form. Equivalent to the array form of the workspaces field.
# Example
"workspaces.packages":
- "packages/*"
Deprecated workspace globs that should not be hoisted.
This legacy field is accepted so Yarn can warn about it, but it isn't honored. Use installConfig.hoistingLimits instead.
# Example
"workspaces.nohoist":
- "**/react-native"
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.
Each key is a package name (glob patterns such as @babel/* are accepted), optionally followed by @ and a semver range to only cover some versions of the package (yarn unplug writes keys such as nan@2.17.0).
# 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
# Allow the build scripts of a specific version range.
dependenciesMeta:
"esbuild@^0.25.0":
built: true
Define whether to run the postinstall script or not.
If true, the build scripts of the package run even though the enableScripts yarnrc setting is disabled (which is the default), making built an allow-list. If false, they never run, even when enableScripts is enabled. When omitted, enableScripts decides. The scripts of workspaces always run.
# Example
"dependenciesMeta[name].built": false
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).
# Example
"dependenciesMeta[name].unplugged": true
Define whether the package is only downloaded once its binaries are called.
If true, the package is still resolved and locked, and downloaded when it's added to the project so that the lockfile records its checksum (except for the packages that only apply to some systems, such as the per-platform builds of @yarnpkg/node, whose checksums the lockfile doesn't record), but installs that don't find it in the cache skip it. Its binaries, which the lockfile lists, download it on their first call, without running an install: the package is extracted to the location the last install reserved for it, from which it can be required too, and the next install links it like any other package. Until it's downloaded, the package can only be used through its binaries. yarn install --fetch-lazy downloads all the lazy packages at once. The packages providing the engines of the project (the .node-version and .python-version files, which install @yarnpkg/node and @yarnpkg/python) are lazy unless this is set to false.
# Example
"dependenciesMeta[name].lazy": true
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.
# Example
"peerDependenciesMeta[name].optional": true
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.
# Example
preferUnplugged: false
Define whether Yarn should run node-gyp rebuild for a package with a binding.gyp file.
When a package has a binding.gyp file at its root but no preinstall, install, or postinstall script, Yarn builds it by running node-gyp rebuild, as npm does.
The gypfile field lets you skip this by setting it to false, for example when your package ships prebuilt binaries. Any other value keeps the default behavior.
# Example
gypfile: false
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. Patterns starting with ! exclude the matching files instead. 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 files are handled regardless of the files array: package.json, the readme, license, and changelog files, and the entry points referenced by main, module, exports, imports, browser, bin, publishConfig.types, and publishConfig.typings are always included, while .gitignore, .npmignore, .yarnrc, yarn.lock, .pnp.*, *.tsbuildinfo, .DS_Store, and .#* files are always excluded.
# 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.
The bin, browser, exports, imports, main, module, type, types, and typings fields replace the top-level fields of the same name in the manifest stored in the tarball generated by yarn pack and yarn npm publish. The other fields configure the packing and publishing process itself.
# 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).
# Example
"publishConfig.access": "public"
Replacement of the package's bin field, used in the published tarball over the main one.
Accepts the same formats as the top-level bin field.
# Example
"publishConfig.bin": "./build/bin.js"
Replacement of the package's browser field, used in the published tarball over the main one.
Accepts the same formats as the top-level browser field.
# Example
"publishConfig.browser": "./build/browser.js"
Set of files that must be marked as executable (+x) in the published tarball.
Paths are relative to the package folder. The files referenced by the bin field are always marked as executable, so they don't need to be listed here.
# Example
"publishConfig.executableFiles":
- "dist/shim.js"
Replacement of the package's exports field, used in the published tarball over the main one.
Accepts the same formats as the top-level exports field.
# Example
"publishConfig.exports": "./build/index.js"
Replacement of the package's imports field, used in the published tarball over the main one.
Accepts the same formats as the top-level imports field.
# Example
"publishConfig.imports":
"#internal": "./build/internal.js"
Replacement of the package's main field, used in the published tarball over the main one.
Typically used to point consumers to the build output while the workspace's own main field points to the sources.
# Example
"publishConfig.main": "./build/index.js"
Replacement of the package's module field, used in the published tarball over the main one.
Typically used to point consumers to the build output while the workspace's own module field points to the sources.
# Example
"publishConfig.module": "./build/index.mjs"
Define whether to produce a provenance statement for the package when publishing. Overrides all other provenance settings.
If set, it takes precedence over the --provenance flag of yarn npm publish. Generating a provenance statement requires an OIDC identity token, such as the one GitHub Actions provides to workflows with the id-token: write permission.
# Example
"publishConfig.provenance": true
Registry to which the package is published.
If present, will replace whatever registry is defined in the configuration when the package is about to be pushed to a remote location.
# Example
"publishConfig.registry": "https://npm.pkg.github.com"
Replacement of the package's type field, used in the published tarball over the main one.
Useful when the published build uses a different module format than the sources.
# Example
"publishConfig.type": "module"
Replacement of the package's types field, used in the published tarball over the main one.
The referenced file is always included in the tarball, regardless of the files field.
# Example
"publishConfig.types": "./build/index.d.ts"
Replacement of the package's typings field, used in the published tarball over the main one.
The referenced file is always included in the tarball, regardless of the files field.
# Example
"publishConfig.typings": "./build/index.d.ts"
Extra settings affecting how the package is installed.
Omitted or null overrides inherit nmHoistingLimits and nmSelfReferences from the yarnrc configuration.
# 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.
# Example
"installConfig.hoistingLimits": "none"
Defines whether workspaces are allowed to require themselves.
See nmSelfReferences for more information.
# Example
"installConfig.selfReferences": true