メインコンテンツまでスキップ
Version: Next

.npmrc

pnpm は、コマンド行、環境変数、および .npmrc ファイルから設定を取得します。

pnpm config コマンドを使用して、ユーザーおよびグローバルの .npmrc ファイルの内容を更新および編集することができます。

関連する4つのファイルは次のとおりです。

  • プロジェクトごとの設定ファイル(/path/to/my/project/.npmrc)
  • ワークスペースごとの設定ファイル (pnpm-workspace.yaml ファイルが含まれているディレクトリー)
  • ユーザーごとの設定ファイル(~/.npmrc)
  • グローバルな設定ファイル (/etc/npmrc)

.npmrc ファイルはすべて key = value という INI形式 のパラメータのリストです。

.npmrc ファイルの値には、 ${NAME} 構文を使用して環境変数を含めることができます。 また、 環境変数はデフォルト値と共に指定することもできます。 ${NAME-fallback} は、 NAME が設定されていない場合、fallback を返します。 ${NAME:-fallback}NAMEが設定されていないか空文字の場合に、fallbackを返します。

依存の巻き上げ設定

hoist

  • デフォルト: true
  • タイプ: boolean

trueの場合、すべての依存関係は node_modules/.pnpm/node_modules に巻き上げられます。 これにより、リストされていない依存に、 node_modules 内のすべてのパッケージからアクセスできるようになります。

hoist-workspace-packages

  • デフォルト: true
  • タイプ: 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

  • デフォルト: ['*']
  • タイプ: string[]

どのパッケージを node_modules/.pnpm/node_modules に巻き上げるかを指定します。 デフォルトでは、全てのパッケージが巻き上げられます。しかし、phantom dependency を持つ、扱いに困るパッケージの存在が分かっている場合には、このオプションにより、それらを除外して巻き上げることができます (推奨)。

例:

hoist-pattern[]=*eslint*
hoist-pattern[]=*babel*

! を使用して巻き上げから除外するパターンを指定することもできます。

例:

hoist-pattern[]=*types*
hoist-pattern[]=!@types/react

public-hoist-pattern

  • デフォルト: ['*eslint*', '*prettier*']
  • タイプ: string[]

hoist-pattern が仮想ストア内の隠しモジュールディレクトリに依存を巻き上げるのに対し、public-hoist-pattern はパターンにマッチする依存をルートのモジュールディレクトリへと巻き上げます。 ルートのモジュールディレクトリへの巻き上げによって、アプリケーションのコードは phantom dependencies へアクセスできるようになります。たとえ依存関係の解決方法が不適切に変更されたとしてもアクセス可能です。

この設定は、依存関係を適切に解決していなくて扱いに困る、プラグイン可能なツールを利用する場合に便利です。

例:

public-hoist-pattern[]=*plugin*

注意: shamefully-hoisttrue に設定するのと public-hoist-pattern* に設定するのは同じ効果があります。

! を使用して巻き上げから除外するパターンを指定することもできます。

例:

public-hoist-pattern[]=*types*
public-hoist-pattern[]=!@types/react

shamefully-hoist

  • デフォルト: false
  • タイプ: Boolean

デフォルトでは、pnpm はそれなりに厳格な node_modules を作成します。依存パッケージは定義されていない依存パッケージへアクセスできますが、node_modules の外からはアクセスできません。 エコシステム内のほとんどのパッケージは、この方法で問題なく動作します。 しかし、ルートの node_modules に依存パッケージが巻き上げられていないと動作しないツールがある場合には、この設定を true にすることで巻き上げることができます。

node_modules に関する設定

store-dir

  • デフォルト:
    • $PNPM_HOME 環境変数が設定されている場合、 $PNPM_HOME/store
    • $XDG_DATA_HOME 環境変数が設定されている場合、 $XDG_DATA_HOME/pnpm/store
    • Windowsの場合: ~/AppData/Local/pnpm/store
    • macOSの場合: ~/Library/pnpm/store
    • Linuxの場合: ~/.local/share/pnpm/store
  • タイプ: path

パッケージをディスク上のどこに保存するか指定します。

ストアはインストールを行うのと同じディスク状にある必要があります。つまり、ディスクごとに一つのストアを持つことになります。 現在のディスクにホームディレクトリがある場合は、その中にストアが作成されます。 ディスク上にホームディレクトリがない場合は、ストアはファイルシステムのルートに作られます。 例えば、/mnt にマウントされたファイルシステム上でインストールを行なった場合、ストアは /mnt/.pnpm-store に作られます。 Windows システムでも同様です。

異なるディスク上のストアを指定することも可能ですが、その場合 pnpm はハードリンクをせずにパッケージをコピーします。これは、ハードリンクは同一のファイルシステム上でのみ使用可能なためです。

modules-dir

  • デフォルト: node_modules
  • タイプ: path

(node_modules の代わりに) 依存パッケージをインストールする場所を指定します。

node-linker

  • デフォルト: isolated
  • タイプ: isolated, hoisted, pnp

Node.js のパッケージをインストールするのに使用するリンカーを指定します。

  • isolated - 依存関係は node_modules/.pnpm の仮想ストアからシンボリックリンクでインストールされます。
  • hoisted - シンボリックリンクは作成されず、フラットな node_modules が作成されます。 npm や Yarn Classic によって作成される node_modules と同じです。 この設定を使用すると、Yarnのライブラリーの 1 つが巻き上げに使用されます。 この設定を使用する合理的な理由は以下のとおりです:
    1. 使っているツールはシンボリックリンクではうまく機能しない。 React Native のプロジェクトは、おそらく、巻き上げられた(hoisted) node_modulesを使用する場合にのみ機能します。
    2. プロジェクトがサーバーレスホスティングにデプロイされる。 一部のサーバーレスサービスの提供者 (AWS Lambdaなど) はシンボリックリンクをサポートしていません。 この問題を解決する代替策は、デプロイ前にアプリケーションをバンドルすることです。
    3. "bundledDependencies" としてパッケージを公開したい場合
    4. --preserve-symlinks フラグを指定して Node.js を実行している場合。
  • pnp - node_modules なし。 Plug'n'Play は Yarn で使用されている Node のための革新的な方式です。 pnp をリンカーとして使う場合には、 symlinkfalse に設定することが推奨されます。
  • デフォルト: true
  • タイプ: Boolean

symlinkfalse に設定すると、pnpm は仮想ストアのディレクトリをシンボリックリンクを用いずに構成します。 この設定は node-linker=pnp と組み合わせる際に役立ちます。

enable-modules-dir

  • デフォルト: true
  • タイプ: Boolean

false を設定すると、pnpm はモジュールディレクトリ (node_modules) にファイルを一切書き込みません。 この設定はユーザスペース上のファイルシステム (FUSE) にモジュールディレクトリがマウントされている場合に有用です。 node_module ディレクトリを FUSE でマウントするのに使える実験的な CLIツールがあります: @pnpm/mount-modules

virtual-store-dir

  • デフォルト: node_modules/.pnpm
  • タイプ: path

ストアにリンクするディレクトリを指定する。 すべてのプロジェクトの直接および間接的な依存はこのディレクトリへリンクされる。

Windows 上でのパスの長さ上限に関する問題を解決するのに役立ちます。 何らかの非常に長いパスを持つ依存がある場合、ドライブ上のルートに仮想ストアを置くことが可能です。 (例: C:\my-project-store)

もしくは、仮想ストアを .pnpm にして .gitignore に追記することもできます。 依存のディレクトリをひとつ上にすることで、スタックトレース上での表示がすっきりします。

注意: 仮想ストアは複数のプロジェクト間で共有することはできません。 すべてのプロジェクトはそれぞれ固有の仮想ストアを持つ必要があります。 (ルートが共通のワークスペース内のプロジェクトは除く)

package-import-method

  • デフォルト: auto
  • タイプ: 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 - ストアからパッケージをクローンしようとします。 クローンがサポートされていない場合、ストアからパッケージをハードリンクします。 クローンもリンクもできない場合は、コピーします。
  • hardlink - ストアからパッケージをハードリンクします。
  • clone-or-copy - ストアからパッケージをクローンしようとします。 クローンがサポートされていない場合、コピーにフォールバックします。
  • copy - ストアからパッケージをコピーします。
  • clone - ストアからパッケージをクローンします。 (別名: copy-on-write、 参照リンク)

クローンはパッケージを node_modules に書き込む最良の方法です。 最速かつ最も安全です。 クローンを使用している場合、node_modules 内のファイルを編集可能です(編集しても中央ストア側のファイルは変更されません)。

残念ながら、すべてのファイル システムがクローン作成をサポートしているわけではありません。 pnpmで最高の経験をするためには、コピーオンライト (CoW) ファイルシステム (例えばLinuxでは Ext4 の代わりに Btrfs) を使用することをお勧めします。

modules-cache-max-age

  • デフォルト: 10080 (単位は分、7 日)
  • タイプ: number

孤立したパッケージを node_module ディレクトリから削除するまでの時間を分単位で指定します。 pnpm はパッケージのキャッシュを node_module ディレクトリに保持します。 これにより、ブランチを切り替えたり、依存のダウングレードを行う際のインストールのスピードを速くします。

ロックファイル設定

lockfile

  • デフォルト: true
  • タイプ: Boolean

false に設定すると、pnpm は pnpm-lock.yaml を読み込んだり、書き込んだりしません。

prefer-frozen-lockfile

  • デフォルト: true
  • タイプ: Boolean

true に設定すると、pnpm-lock.yaml が存在して、 package.json の依存指定の条件を満たす場合に、ヘッドレスインストールを行います。 ヘッドレスインストールでは、lockfile を変更する必要がないため、すべての依存関係の解決がスキップされます。

lockfile-include-tarball-url

  • デフォルト: false
  • タイプ: Boolean

pnpm-lock.yamlのすべてのエントリに、パッケージの tarball への完全な URL を追加します。

git-branch-lockfile

  • デフォルト: false
  • タイプ: 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

  • デフォルト: 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.

例:

merge-git-branch-lockfiles-branch-pattern[]=main
merge-git-branch-lockfiles-branch-pattern[]=release*

You may also exclude patterns using !.

レジストリ & 認証設定

registry

npm パッケージレジストリのベースURL (末尾のスラッシュを含む)。

<scope>:registry

特定のスコープのパッケージに対して使うレジストリ。 例えば、 @babel:registry=https://example.com/packages/npm/ を設定すると、pnpm add @babel/core やその他の @babel スコープのパッケージをインストールする際に、デフォルトのレジストリの代わりに https://example.com/packages/npm を使うように強制します。

<URL>:_authToken

レジストリにアクセスするときに使用する認証用の Bearer トークンを指定します。 例:

//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 

環境変数を使用することもできます。 例:

//registry.npmjs.org/:_authToken=${NPM_TOKEN}

あるいは、 .npmrc をまったく変更せずに、環境変数を直接使用することもできます。

npm_config_//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 

<URL>:tokenHelper

tokenHelper とは、アクセストークンを出力する実行ファイルです。 これは、authToken が一定値ではなく定期的に更新されるような場合に使用します。 スクリプトやその他のツールが、既存のリフレッシュトークンを使って新しいアクセストークンを取得できるようになります。

helper へのパスの設定は、引数なしの絶対パスである必要があります。 安全性を高めるため、この値はユーザーの .npmrc にのみ設定することが許されています。 そうしないと、プロジェクトがプロジェクトのローカルの .npmrc に値を置いて、任意の実行ファイルを実行することができてしまいます。

デフォルトのレジストリに tokenHelper を設定します:

tokenHelper=/home/ivan/token-generator

指定されたレジストリに tokenHelper を設定します:

//registry.corp.com:tokenHelper=/home/ivan/token-generator

リクエスト設定

ca

  • デフォルト: npm CA 証明書
  • タイプ: String, Array, null

レジストリへのSSL接続をするのに信用する署名用CA証明書を指定します。 値は PEM フォーマット (Base64エンコードされた X.509 (.CER)) で指定します。 例:

ca="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"

Null に設定すると、既知の登録者のみを許可できます。もしくは、特定の CA 証明書の署名のみを信頼するように設定できます。

証明書の配列を指定することで、複数の信頼する CA を指定することもできます。

ca[]="..."
ca[]="..."

strict-ssl も参照してください。

cafile

  • デフォルト: null
  • タイプ: path

ひとつ、もしくは複数のCA 署名用証明書を持つファイルへのパスを指定します。 ca 設定と同様ですが、複数の CA に関する情報を CLI 経由ではなくファイルに保持しておくことができます。

<URL>:cafile

Define the path to a Certificate Authority file to use when accessing the specified registry. 例:

//registry.npmjs.org/:keyfile=client-cert.pem

cert

  • デフォルト: null
  • タイプ: String

レジストリにアクセスするときに渡すクライアント証明書。 値は PEM フォーマット (Base64エンコードされた X.509 (.CER)) で指定します。 例:

cert="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"

It is not the path to a certificate file.

<URL>:certfile

Define the path to a certificate file to use when accessing the specified registry. 例:

//registry.npmjs.org/:certfile=server-cert.pem

key

  • デフォルト: null
  • タイプ: String

レジストリにアクセスするときに渡すクライアントキー。 値は PEM フォーマット (Base64エンコードされた X.509 (.CER)) で指定します。 例:

key="-----BEGIN PRIVATE KEY-----\nXXXX\nXXXX\n-----END PRIVATE KEY-----"

キーファイルへのパスではありません (keyfile オプションはありません)。

この設定には機密情報が含まれています。 リポジトリにコミットされたローカルの .npmrc ファイルに書き込まないでください。

<URL>:keyfile

Define the path to a client key file to use when accessing the specified registry. 例:

//registry.npmjs.org/:keyfile=server-key.pem

git-shallow-hosts

  • デフォルト: ['github.com', 'gist.github.com', 'gitlab.com', 'bitbucket.com', 'bitbucket.org']
  • タイプ: string[]

Git リポジトリである依存関係を取得する際、この設定でホストがリストアップされている場合、pnpm は浅いクローン(シャロークローン) を用いて、すべての履歴ではなく、必要なコミットのみを取得するようにします。

https-proxy

  • デフォルト: null
  • タイプ: url

送信する HTTPS リクエストに使用するプロキシ。 HTTPS_PROXYhttps_proxyHTTP_PROXY 、または http_proxy 環境変数が設定されている場合は、その値が代わりに使用されます。

プロキシ URL にユーザー名とパスワードが含まれている場合は、必ず URL エンコードしてください。 例:

https-proxy=https://use%21r:pas%2As@my.proxy:1234/foo

ユーザー名とパスワードの間のコロン (:) をエンコードしないでください。

http-proxy

proxy

  • デフォルト: null
  • タイプ: url

送信する HTTP リクエストに使用するプロキシ。 HTTP_PROXY または http_proxy 環境変数が設定されている場合、プロキシー設定は、内部のリクエストライブラリーに受け渡されます。

local-address

  • デフォルト: undefined
  • タイプ: IP Address

npm レジストリへの接続を行うときに使用するローカルインターフェイスのIPアドレス。

maxsockets

  • デフォルト: network-concurrency x 3
  • タイプ: Number

origin (protocol/host/port の組み合わせ) ごとに使用する最大接続数です。

noproxy

  • デフォルト: null
  • タイプ: String

プロキシーを使わない TLD をコンマ区切りの文字列で指定します。

strict-ssl

  • デフォルト: true
  • タイプ: Boolean

HTTPS 経由でレジストリにリクエストを送る際にSSL鍵の検証を行うかどうかを指定します。

ca オプションも参照してください。

network-concurrency

  • デフォルト: 16
  • タイプ: Number

同時に処理する HTTP(S) のリクエストの最大数を制御します。

fetch-retries

  • デフォルト: 2
  • タイプ: Number

pnpm がレジストリからの取得に失敗した際に何回リトライするかを指定する。

fetch-retry-factor

  • デフォルト: 10
  • タイプ: Number

再試行間隔の指数関数バックオフ (Exponential Backoff) に使用する係数。

fetch-retry-mintimeout

  • デフォルト: 10000 (10 秒)
  • タイプ: Number

リクエストをリトライする際の最小(最初) のタイムアウト。

fetch-retry-maxtimeout

  • デフォルト: 60000 (1 分)
  • タイプ: Number

リクエストが長時間リトライされないということがないようにするためのフォールバック用の最大タイムアウト。(訳注: fetch-retry-factor のExponential Backoffによってリトライ間隔は徐々に長くなっていくため、その上限を設ける設定)

fetch-timeout

  • デフォルト: 60000 (1 分)
  • タイプ: Number

HTTP リクエストが完了するまでに待つ最大の時間。

Peer Dependency Settings

auto-install-peers

  • デフォルト: true
  • タイプ: Boolean

true の場合、不足している Optional ではない peer dependencies が自動的にインストールされます。

Version Conflicts

If there are conflicting version requirements for a peer dependency from different packages, pnpm will not install any version of the conflicting peer dependency automatically. Instead, a warning is printed. For example, if one dependency requires react@^16.0.0 and another requires react@^17.0.0, these requirements conflict, and no automatic installation will occur.

Conflict Resolution

In case of a version conflict, you'll need to evaluate which version of the peer dependency to install yourself, or update the dependencies to align their peer dependency requirements.

dedupe-peer-dependents

  • デフォルト: true
  • タイプ: Boolean

この設定が trueに設定されている場合、peer dependencies を持つパッケージは、ピアの解決後に重複排除されます。

例えば、2つのプロジェクトを持つワークスペースがあり、どちらもその依存関係に webpack を持っているとしましょう。 webpackesbuildをオプションの peer dependencies に持ち、2つのうち片方のプロジェクトは依存関係に esbuild を持っている。 この場合、 pnpm は webpack の 2 つのインスタンスを node_modules/.pnpm ディレクトリーにリンクします。 1 つは esbuild と一緒に。もう 1 つはそれ抜きで。

node_modules
.pnpm
webpack@1.0.0_esbuild@1.0.0
webpack@1.0.0
project1
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0/node_modules/webpack
project2
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
esbuild

これは意図した挙動です。webpack が 2 つのプロジェクトで使用されており、片方のプロジェクトには esbuild が含まれていないため、 2 つのプロジェクトは同じwebpackインスタンスを共有することができませんので。 しかし、これはほとんどの開発者が期待しているものではありません。特に巻き上げられた(hoisted) node_modulesの場合は、 結局webpack のインスタンスが 1 つのみ存在することになるためです。 そのため、 競合する peer dependencies がないときは、deduupe-peer-dependents 設定を使用して webpack を重複排除することができます(最後に説明します)。 この例の場合、 dedupe-peer-dependentstrueに設定すると、両方のプロジェクトが同じ webpack インスタンスを使用し、これは esbuild が解決されています:

node_modules
.pnpm
webpack@1.0.0_esbuild@1.0.0
project1
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
project2
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
esbuild

競合する peer dependencies とは何か? 競合する peer dependencies とは、次のようなシナリオを意味します:

node_modules
.pnpm
webpack@1.0.0_react@16.0.0_esbuild@1.0.0
webpack@1.0.0_react@17.0.0
project1
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0/node_modules/webpack
react (v17)
project2
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
esbuild
react (v16)

この場合、 webpack の peer dependencies に react があり、 react は 2 つのプロジェクトのコンテキストで 2 つの異なるバージョンから解決されるため、 webpack を重複排除できません。

strict-peer-dependencies

  • デフォルト: false
  • タイプ: Boolean

このオプションを有効にすると、依存関係ツリーに欠落していたり無効な peer dependency が存在すると、コマンドが失敗するようになります。

resolve-peers-from-workspace-root

  • デフォルト: true
  • タイプ: Boolean

有効にすると、ワークスペース内のプロジェクトのpeer dependenciesを解決に、ルートワークスペースプロジェクトの依存関係を使用するようになります。 peer dependencies をワークスペースのルートにのみインストールでき、ワークスペース内のすべてのプロジェクトが同じバージョンのpeer dependencies を使用していることを確実にできるため、これは便利な機能です。

CLI 設定

[no-]color

  • デフォルト: auto
  • タイプ: auto, always, never

出力時の色を制御します。

  • auto - 標準出力がターミナルかTTYの場合は、出力に色を使用します。
  • always - ターミナルとパイプの違いを無視します。 これが必要になることはめったにありません。ほとんどの場合では、リダイレクトされた出力にカラーコードを含めたい場合、pnpm コマンドに --colorフラグを指定し、 pnpmコマンドにカラーコードを使用することを強制させることで代用できます。 ほとんどの場合デフォルトの設定があなたの求めているものでしょう。
  • never - turns off colors. This is the setting used by --no-color.

loglevel

  • Default: info
  • Type: debug, info, warn, error

Any logs at or higher than the given level will be shown. You can instead pass --silent to turn off all output logs.

use-beta-cli

  • デフォルト: false
  • タイプ: Boolean

Experimental option that enables beta features of the CLI. This means that you may get some changes to the CLI functionality that are breaking changes, or potentially bugs.

recursive-install

  • デフォルト: true
  • タイプ: Boolean

If this is enabled, the primary behaviour of pnpm install becomes that of pnpm install -r, meaning the install is performed on all workspace or subdirectory packages.

Else, pnpm install will exclusively build the package in the current directory.

engine-strict

  • デフォルト: false
  • タイプ: Boolean

If this is enabled, pnpm will not install any package that claims to not be compatible with the current Node version.

Regardless of this configuration, installation will always fail if a project (not a dependency) specifies an incompatible version in its engines field.

npm-path

  • タイプ: path

The location of the npm binary that pnpm uses for some actions, like publishing.

ビルド設定

ignore-scripts

  • デフォルト: false
  • タイプ: Boolean

すべてのパッケージ、および依存パッケージで package.json に定義されているスクリプトを実行しません。

メモ

This flag does not prevent the execution of .pnpmfile.cjs

ignore-dep-scripts

  • デフォルト: false
  • タイプ: Boolean

Do not execute any scripts of the installed packages. Scripts of the projects are executed.

child-concurrency

  • Default: 5
  • タイプ: Number

The maximum number of child processes to allocate simultaneously to build node_modules.

side-effects-cache

  • デフォルト: true
  • タイプ: Boolean

Use and cache the results of (pre/post)install hooks.

side-effects-cache-readonly

  • デフォルト: false
  • タイプ: Boolean

Only use the side effects cache if present, do not create it for new packages.

unsafe-perm

  • Default: false IF running as root, ELSE true
  • タイプ: Boolean

Set to true to enable UID/GID switching when running package scripts. If set explicitly to false, then installing as a non-root user will fail.

node-options

  • Default: NULL
  • タイプ: String

Options to pass through to Node.js via the NODE_OPTIONS environment variable. This does not impact how pnpm itself is executed but it does impact how lifecycle scripts are called.

Node.js Settings

use-node-version

  • デフォルト: undefined
  • Type: semver

Specifies which exact Node.js version should be used for the project's runtime. pnpm will automatically install the specified version of Node.js and use it for running pnpm run commands or the pnpm node command.

This may be used instead of .nvmrc and nvm. Instead of the following .nvmrc file:

16.16.0

Use this .npmrc file:

use-node-version=16.16.0

node-version

  • Default: the value returned by node -v, without the v prefix
  • Type: semver

The Node.js version to use when checking a package's engines setting.

If you want to prevent contributors of your project from adding new incompatible dependencies, use node-version and engine-strict in a .npmrc file at the root of the project:

node-version=12.22.0
engine-strict=true

This way, even if someone is using Node.js v16, they will not be able to install a new dependency that doesn't support Node.js v12.22.0.

node-mirror:<releaseDir>

  • Default: https://nodejs.org/download/<releaseDir>/
  • Type: URL

Sets the base URL for downloading Node.js. The <releaseDir> portion of this setting can be any directory from https://nodejs.org/download: release, rc, nightly, v8-canary, etc.

Here is how pnpm may be configured to download Node.js from Node.js mirror in China:

node-mirror:release=https://npmmirror.com/mirrors/node/
node-mirror:rc=https://npmmirror.com/mirrors/node-rc/
node-mirror:nightly=https://npmmirror.com/mirrors/node-nightly/

ワークスペース設定

  • デフォルト: false
  • Type: true, false, deep

If this is enabled, locally available packages are linked to node_modules instead of being downloaded from the registry. This is very convenient in a monorepo. If you need local packages to also be linked to subdependencies, you can use the deep setting.

Else, packages are downloaded and installed from the registry. However, workspace packages can still be linked by using the workspace: range protocol.

prefer-workspace-packages

  • デフォルト: false
  • タイプ: Boolean

If this is enabled, local packages from the workspace are preferred over packages from the registry, even if there is a newer version of the package in the registry.

This setting is only useful if the workspace doesn't use save-workspace-protocol.

shared-workspace-lockfile

  • デフォルト: true
  • タイプ: Boolean

If this is enabled, pnpm creates a single pnpm-lock.yaml file in the root of the workspace. This also means that all dependencies of workspace packages will be in a single node_modules (and get symlinked to their package node_modules folder for Node's module resolution).

Advantages of this option:

  • every dependency is a singleton
  • faster installations in a monorepo
  • fewer changes in code reviews as they are all in one file
メモ

Even though all the dependencies will be hard linked into the root node_modules, packages will have access only to those dependencies that are declared in their package.json, so pnpm's strictness is preserved. This is a result of the aforementioned symbolic linking.

save-workspace-protocol

  • Default: rolling
  • Type: true, false, rolling

This setting controls how dependencies that are linked from the workspace are added to package.json.

If foo@1.0.0 is in the workspace and you run pnpm add foo in another project of the workspace, below is how foo will be added to the dependencies field. The save-prefix setting also influences how the spec is created.

save-workspace-protocolsave-prefixspec
false''1.0.0
false'~'~1.0.0
false'^'^1.0.0
true''workspace:1.0.0
true'~'workspace:~1.0.0
true'^'workspace:^1.0.0
rolling''workspace:*
rolling'~'workspace:~
rolling'^'workspace:^

include-workspace-root

  • デフォルト: false
  • タイプ: Boolean

When executing commands recursively in a workspace, execute them on the root workspace project as well.

ignore-workspace-cycles

  • デフォルト: false
  • タイプ: Boolean

trueに設定すると、ワークスペースの循環参照警告は出力されません。

disallow-workspace-cycles

  • デフォルト: false
  • タイプ: Boolean

When set to true, installation will fail if the workspace has cycles.

その他の設定

use-running-store-server

  • デフォルト: false
  • タイプ: Boolean

Only allows installation with a store server. If no store server is running, installation will fail.

save-prefix

  • Default: '^'
  • Type: '^', '~', ''

Configure how versions of packages installed to a package.json file get prefixed.

For example, if a package has version 1.2.3, by default its version is set to ^1.2.3 which allows minor upgrades for that package, but after pnpm config set save-prefix='~' it would be set to ~1.2.3 which only allows patch upgrades.

This setting is ignored when the added package has a range specified. For instance, pnpm add foo@2 will set the version of foo in package.json to 2, regardless of the value of save-prefix.

tag

  • Default: latest
  • タイプ: String

If you pnpm add a package and you don't provide a specific version, then it will install the package at the version registered under the tag from this setting.

This also sets the tag that is added to the package@version specified by the pnpm tag command if no explicit tag is given.

global-dir

  • デフォルト:
    • If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm/global
    • On Windows: ~/AppData/Local/pnpm/global
    • On macOS: ~/Library/pnpm/global
    • On Linux: ~/.local/share/pnpm/global
  • タイプ: path

Specify a custom directory to store global packages.

global-bin-dir

  • デフォルト:
    • If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm
    • On Windows: ~/AppData/Local/pnpm
    • On macOS: ~/Library/pnpm
    • On Linux: ~/.local/share/pnpm
  • タイプ: path

Allows to set the target directory for the bin files of globally installed packages.

state-dir

  • デフォルト:
    • If the $XDG_STATE_HOME env variable is set, then $XDG_STATE_HOME/pnpm
    • On Windows: ~/AppData/Local/pnpm-state
    • On macOS: ~/.pnpm-state
    • On Linux: ~/.local/state/pnpm
  • タイプ: path

The directory where pnpm creates the pnpm-state.json file that is currently used only by the update checker.

cache-dir

  • デフォルト:
    • If the $XDG_CACHE_HOME env variable is set, then $XDG_CACHE_HOME/pnpm
    • On Windows: ~/AppData/Local/pnpm-cache
    • On macOS: ~/Library/Caches/pnpm
    • On Linux: ~/.cache/pnpm
  • タイプ: path

The location of the package metadata cache.

use-stderr

  • デフォルト: false
  • タイプ: Boolean

When true, all the output is written to stderr.

update-notifier

  • デフォルト: true
  • タイプ: Boolean

Set to false to suppress the update notification when using an older version of pnpm than the latest.

prefer-symlinked-executables

  • Default: true, when node-linker is set to hoisted and the system is POSIX
  • タイプ: Boolean

Create symlinks to executables in node_modules/.bin instead of command shims. This setting is ignored on Windows, where only command shims work.

verify-store-integrity

  • デフォルト: true
  • タイプ: 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.

ignore-compatibility-db

  • デフォルト: false
  • タイプ: Boolean

During installation the dependencies of some packages are automatically patched. If you want to disable this, set this config to false.

The patches are applied from Yarn's @yarnpkg/extensions package.

resolution-mode

  • Default: highest (was lowest-direct from v8.0.0 to v8.6.12)
  • Type: highest, time-based, lowest-direct

When resolution-mode is set to time-based, dependencies will be resolved the following way:

  1. 直接の依存関係は、最も低いバージョンに解決されます。 そのため、依存関係に foo@^ 1.1.0 がある場合は、 1.1.0 がインストールされます。
  2. 従属依存関係 (訳注: 依存関係の依存関係) は、最後の直接の依存関係がパブリッシュされる前にパブリッシュされたバージョンから解決されます。

With this resolution mode installations with warm cache are faster. It also reduces the chance of subdependency hijacking as subdependencies will be updated only if direct dependencies are updated.

This resolution mode works only with npm's full metadata. So it is slower in some scenarios. However, if you use Verdaccio v5.15.1 or newer, you may set the registry-supports-time-field setting to true, and it will be really fast.

When resolution-mode is set to lowest-direct, direct dependencies will be resolved to their lowest versions.

registry-supports-time-field

  • デフォルト: false
  • タイプ: Boolean

Set this to true if the registry that you are using returns the "time" field in the abbreviated metadata. As of now, only Verdaccio from v5.15.1 supports this.

extend-node-path

  • デフォルト: true
  • タイプ: Boolean

When false, the NODE_PATH environment variable is not set in the command shims.

deploy-all-files

  • デフォルト: false
  • タイプ: Boolean

When deploying a package or installing a local package, all files of the package are copied. By default, if the package has a "files" field in the package.json, then only the listed files and directories are copied.

dedupe-direct-deps

  • デフォルト: false
  • タイプ: Boolean

When set to true, dependencies that are already symlinked to the root node_modules directory of the workspace will not be symlinked to subproject node_modules directories.

dedupe-injected-deps

  • デフォルト: true
  • タイプ: Boolean

When this setting is enabled, dependencies that are injected will be symlinked from the workspace whenever possible. If the dependent project and the injected dependency reference the same peer dependencies, then it is not necessary to physically copy the injected dependency into the dependent's node_modules; a symlink is sufficient.

package-manager-strict

  • デフォルト: true
  • タイプ: Boolean

When this setting is disabled, pnpm will not fail if its version doesn't match the one specified in the packageManager field of package.json.

Alternatively, you can set the COREPACK_ENABLE_STRICT environment variable to 0.