Settings (.npmrc)
pnpm gets its configuration from the command line, environment variables, and
.npmrc
files.
The pnpm config
command can be used to update and edit the contents of the
user and global .npmrc
files.
The four relevant files are:
- per-project configuration file (
/path/to/my/project/.npmrc
) - per-workspace configuration file (the directory that contains the
pnpm-workspace.yaml
file) - per-user configuration file (
~/.npmrc
) - global configuration file (
/etc/npmrc
)
All .npmrc
files are an INI-formatted list of key = value
parameters.
Values in the .npmrc
files may contain env variables using the ${NAME}
syntax. The env variables may also be specified with default values. Using ${NAME-fallback}
will return fallback
if NAME
isn't set. ${NAME:-fallback}
will return fallback
if NAME
isn't set, or is an empty string.
Dependency Hoisting Settings
hoist
- Default: true
- Type: boolean
When true
, all dependencies are hoisted to node_modules/.pnpm/node_modules
. This makes
unlisted dependencies accessible to all packages inside node_modules
.
hoist-workspace-packages
- Default: true
- Type: boolean
When true
, packages from the workspaces are symlinked to either <workspace_root>/node_modules/.pnpm/node_modules
or to <workspace_root>/node_modules
depending on other hoisting settings (hoist-pattern
and public-hoist-pattern
).
hoist-pattern
- Default: ['*']
- Type: string[]
Tells pnpm which packages should be hoisted to node_modules/.pnpm/node_modules
. By
default, all packages are hoisted - however, if you know that only some flawed
packages have phantom dependencies, you can use this option to exclusively hoist
the phantom dependencies (recommended).
For instance:
hoist-pattern[]=*eslint*
hoist-pattern[]=*babel*
You may also exclude patterns from hoisting using !
.
For instance:
hoist-pattern[]=*types*
hoist-pattern[]=!@types/react
public-hoist-pattern
- Default: ['*eslint*', '*prettier*']
- Type: string[]
Unlike hoist-pattern
, which hoists dependencies to a hidden modules directory
inside the virtual store, public-hoist-pattern
hoists dependencies matching
the pattern to the root modules directory. Hoisting to the root modules
directory means that application code will have access to phantom dependencies,
even if they modify the resolution strategy improperly.
This setting is useful when dealing with some flawed pluggable tools that don't resolve dependencies properly.
For instance:
public-hoist-pattern[]=*plugin*
Note: Setting shamefully-hoist
to true
is the same as setting
public-hoist-pattern
to *
.
You may also exclude patterns from hoisting using !
.
For instance:
public-hoist-pattern[]=*types*
public-hoist-pattern[]=!@types/react
shamefully-hoist
- Default: false
- Type: Boolean
By default, pnpm creates a semistrict node_modules
, meaning dependencies have
access to undeclared dependencies but modules outside of node_modules
do not.
With this layout, most of the packages in the ecosystem work with no issues.
However, if some tooling only works when the hoisted dependencies are in the
root of node_modules
, you can set this to true
to hoist them for you.
Node-Modules Settings
modules-dir
- Default: node_modules
- Type: path
The directory in which dependencies will be installed (instead of
node_modules
).
node-linker
- Default: isolated
- Type: isolated, hoisted, pnp
Defines what linker should be used for installing Node packages.
- isolated - dependencies are symlinked from a virtual store at
node_modules/.pnpm
. - hoisted - a flat
node_modules
without symlinks is created. Same as thenode_modules
created by npm or Yarn Classic. One of Yarn's libraries is used for hoisting, when this setting is used. Legitimate reasons to use this setting:- Your tooling doesn't work well with symlinks. A React Native project will most probably only work if you use a hoisted
node_modules
. - Your project is deployed to a serverless hosting provider. Some serverless providers (for instance, AWS Lambda) don't support symlinks. An alternative solution for this problem is to bundle your application before deployment.
- If you want to publish your package with
"bundledDependencies"
. - If you are running Node.js with the --preserve-symlinks flag.
- Your tooling doesn't work well with symlinks. A React Native project will most probably only work if you use a hoisted
- pnp - no
node_modules
. Plug'n'Play is an innovative strategy for Node that is used by Yarn Berry. It is recommended to also setsymlink
setting tofalse
when usingpnp
as your linker.
symlink
- Default: true
- Type: Boolean
When symlink
is set to false
, pnpm creates a virtual store directory without
any symlinks. It is a useful setting together with node-linker=pnp
.
enable-modules-dir
- Default: true
- Type: Boolean
When false
, pnpm will not write any files to the modules directory
(node_modules
). This is useful for when the modules directory is mounted with
filesystem in userspace (FUSE). There is an experimental CLI that allows you to
mount a modules directory with FUSE: @pnpm/mount-modules.
virtual-store-dir
- Default: node_modules/.pnpm
- Types: path
The directory with links to the store. All direct and indirect dependencies of the project are linked into this directory.
This is a useful setting that can solve issues with long paths on Windows. If
you have some dependencies with very long paths, you can select a virtual store
in the root of your drive (for instance C:\my-project-store
).
Or you can set the virtual store to .pnpm
and add it to .gitignore
. This
will make stacktraces cleaner as paths to dependencies will be one directory
higher.
NOTE: the virtual store cannot be shared between several projects. Every project should have its own virtual store (except for in workspaces where the root is shared).
virtual-store-dir-max-length
Added in: v9.1.0
- Default: 120
- Types: number
Sets the maximum allowed length of directory names inside the virtual store directory (node_modules/.pnpm
). You may set this to a lower number if you encounter long path issues on Windows.
package-import-method
- Default: auto
- Type: auto, hardlink, copy, clone, clone-or-copy
Controls the way packages are imported from the store (if you want to disable symlinks inside node_modules
, then you need to change the node-linker setting, not this one).
- auto - try to clone packages from the store. If cloning is not supported then hardlink packages from the store. If neither cloning nor linking is possible, fall back to copying
- hardlink - hard link packages from the store
- clone-or-copy - try to clone packages from the store. If cloning is not supported then fall back to copying
- copy - copy packages from the store
- clone - clone (AKA copy-on-write or reference link) packages from the store
Cloning is the best way to write packages to node_modules. It is the fastest way and safest way. When cloning is used, you may edit files in your node_modules and they will not be modified in the central content-addressable store.
Unfortunately, not all file systems support cloning. We recommend using a copy-on-write (CoW) file system (for instance, Btrfs instead of Ext4 on Linux) for the best experience with pnpm.
modules-cache-max-age
- Default: 10080 (7 days in minutes)
- Type: number
The time in minutes after which orphan packages from the modules directory should be removed. pnpm keeps a cache of packages in the modules directory. This boosts installation speed when switching branches or downgrading dependencies.
dlx-cache-max-age
- Default: 1440 (1 day in minutes)
- Type: number
The time in minutes after which dlx cache expires. After executing a dlx command, pnpm keeps a cache that omits the installation step for subsequent calls to the same dlx command.
Store Settings
store-dir
- Default:
- If the $PNPM_HOME env variable is set, then $PNPM_HOME/store
- If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm/store
- On Windows: ~/AppData/Local/pnpm/store
- On macOS: ~/Library/pnpm/store
- On Linux: ~/.local/share/pnpm/store
- Type: path
The location where all the packages are saved on the disk.
The store should be always on the same disk on which installation is happening,
so there will be one store per disk. If there is a home directory on the current
disk, then the store is created inside it. If there is no home on the disk,
then the store is created at the root of the filesystem. For
example, if installation is happening on a filesystem mounted at /mnt
,
then the store will be created at /mnt/.pnpm-store
. The same goes for Windows
systems.
It is possible to set a store from a different disk but in that case pnpm will copy packages from the store instead of hard-linking them, as hard links are only possible on the same filesystem.
verify-store-integrity
- Default: true
- Type: Boolean
By default, if a file in the store has been modified, the content of this file is checked before linking it to a project's node_modules
. If verify-store-integrity
is set to false
, files in the content-addressable store will not be checked during installation.
use-running-store-server
Deprecated feature
- Default: false
- Type: Boolean
Only allows installation with a store server. If no store server is running, installation will fail.
strict-store-pkg-content-check
Added in: v9.4.0
- Default: true
- Type: Boolean
Some registries allow the exact same content to be published under different package names and/or versions. This breaks the validity checks of packages in the store. To avoid errors when verifying the names and versions of such packages in the store, you may set the strict-store-pkg-content-check
setting to false
.
Lockfile Settings
lockfile
- Default: true
- Type: Boolean
When set to false
, pnpm won't read or generate a pnpm-lock.yaml
file.
prefer-frozen-lockfile
- Default: true
- Type: Boolean
When set to true
and the available pnpm-lock.yaml
satisfies the
package.json
dependencies directive, a headless installation is performed. A
headless installation skips all dependency resolution as it does not need to
modify the lockfile.
lockfile-include-tarball-url
- Default: false
- Type: Boolean
Add the full URL to the package's tarball to every entry in pnpm-lock.yaml
.
git-branch-lockfile
- Default: false
- Type: Boolean
When set to true
, the generated lockfile name after installation will be named
based on the current branch name to completely avoid merge conflicts. For example,
if the current branch name is feature-foo
, the corresponding lockfile name will
be pnpm-lock.feature-foo.yaml
instead of pnpm-lock.yaml
. It is typically used
in conjunction with the command line argument --merge-git-branch-lockfiles
or by
setting merge-git-branch-lockfiles-branch-pattern
in the .npmrc
file.
merge-git-branch-lockfiles-branch-pattern
- Default: null
- Type: Array or null
This configuration matches the current branch name to determine whether to merge
all git branch lockfile files. By default, you need to manually pass the
--merge-git-branch-lockfiles
command line parameter. This configuration allows
this process to be automatically completed.
For instance:
merge-git-branch-lockfiles-branch-pattern[]=main
merge-git-branch-lockfiles-branch-pattern[]=release*
You may also exclude patterns using !
.
peers-suffix-max-length
Added in: v9.3.0
- Default: 1000
- Type: number
Max length of the peer IDs suffix added to dependency keys in the lockfile. If the suffix is longer, it is replaced with a hash.
Registry & Authentication Settings
registry
- Default: https://registry.npmjs.org/
- Type: url
The base URL of the npm package registry (trailing slash included).
<scope>:registry
The npm registry that should be used for packages of the specified scope. For
example, setting @babel:registry=https://example.com/packages/npm/
will enforce that when you use pnpm add @babel/core
, or any @babel
scoped
package, the package will be fetched from https://example.com/packages/npm
instead of the default registry.
<URL>:_authToken
Define the authentication bearer token to use when accessing the specified registry. For example:
//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
You may also use an environment variable. For example:
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
Or you may just use an environment variable directly, without changing .npmrc
at all:
npm_config_//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
<URL>:tokenHelper
A token helper is an executable which outputs an auth token. This can be used in situations where the authToken is not a constant value but is something that refreshes regularly, where a script or other tool can use an existing refresh token to obtain a new access token.
The configuration for the path to the helper must be an absolute path, with no arguments. In order to be secure, it is only permitted to set this value in the user .npmrc
. Otherwise a project could place a value in a project's local .npmrc
and run arbitrary executables.
Setting a token helper for the default registry:
tokenHelper=/home/ivan/token-generator
Setting a token helper for the specified registry:
//registry.corp.com:tokenHelper=/home/ivan/token-generator
Request Settings
ca
- Default: The npm CA certificate
- Type: String, Array or null
The Certificate Authority signing certificate that is trusted for SSL connections to the registry. Values should be in PEM format (AKA "Base-64 encoded X.509 (.CER)"). For example:
ca="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"
Set to null to only allow known registrars, or to a specific CA cert to trust only that specific signing authority.
Multiple CAs can be trusted by specifying an array of certificates:
ca[]="..."
ca[]="..."
See also the strict-ssl
config.
cafile
- Default: null
- Type: path
A path to a file containing one or multiple Certificate Authority signing
certificates. Similar to the ca
setting, but allows for multiple CAs, as well
as for the CA information to be stored in a file instead of being specified via
CLI.
<URL>:cafile
Define the path to a Certificate Authority file to use when accessing the specified registry. For example:
//registry.npmjs.org/:keyfile=client-cert.pem
cert
- Default: null
- Type: String
A client certificate to pass when accessing the registry. Values should be in PEM format (AKA "Base-64 encoded X.509 (.CER)"). For example:
cert="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"