package.json
パッケージに関する情報を記述したファイルです。 タイトル、作者、依存パッケージなどのメタ情報を含んでいます。 This is a standard preserved across all major Node.js package managers, including pnpm.
In addition to the traditional package.json
format, pnpm also supports package.json5
(via json5) and package.yaml
(via js-yaml).
engines
ソフトウェアが(パッケージが)動作するNode.jsとpnpmのバージョンを指定できます。
{
"engines": {
"node": ">=10",
"pnpm": ">=3"
}
}
開発時に使用しているpnpmのバージョンがengines
フィールドに指定したバージョンと一致しない場合、常に失敗し、エラーメッセージを出力するでしょう。
Unless the user has set the engineStrict
config flag (see settings), this field is advisory only and will only produce warnings when your package is installed as a dependency.
devEngines.runtime
Added in: v10.14
Allows to specify one or more JavaScript runtime engines used by the project. Supported runtimes are Node.js, Deno, and Bun.
For instance, here is how to add node@^24.4.0
to your dependencies:
{
"devEngines": {
"runtime": {
"name": "node",
"version": "^24.4.0",
"onFail": "download"
}
}
}
You can also add multiple runtimes to the same package.json
:
{
"devEngines": {
"runtime": [
{
"name": "node",
"version": "^24.4.0",
"onFail": "download"
},
{
"name": "deno",
"version": "^2.4.3",
"onFail": "download"
}
]
}
}
How it works:
pnpm install
resolves your specified range to the latest matching runtime version.- The exact version (and checksum) is saved in the lockfile.
- Scripts use the local runtime, ensuring consistency across environments.
dependenciesMeta
dependencies
, optionalDependencies
, devDependencies
内で宣言された依存関係のために使用される追加のメタ情報です。
dependenciesMeta.*.injected
If this is set to true
for a dependency that is a local workspace package, that package will be installed by creating a hard linked copy in the virtual store (node_modules/.pnpm
).
If this is set to false
or not set, then the dependency will instead be installed by creating a node_modules
symlink that points to the package's source directory in the workspace. This is the default, as it is faster and ensures that any modifications to the dependency will be immediately visible to its consumers.
For example, suppose the following package.json
is a local workspace package:
{
"name": "card",
"dependencies": {
"button": "workspace:1.0.0"
}
}