Skip to main content
版本:7.x

pnpm CLI

與 npm 的差異

與 npm 不同, pnpm 會驗證所有選項。 例如 pnpm install --target_arch x64 會發生錯誤,因為 --target_arch 並非 pnpm install 的合法選項。

然而有些依賴項目可能會使用 npm_config_ 環境變數,其中由 CLI 選項填充。 這時候有兩種做法:

  1. 顯式設定 env 變數:npm_config_target_arch=x64 pnpm install
  2. --config 強制使用未知的選項:pnpm install --config.target_arch=x64

參數選項

-C <path>, --dir <path>

Run as if pnpm was started in <path> instead of the current working directory.

-w, --workspace-root

Run as if pnpm was started in the root of the workspace instead of the current working directory.

可用命令

如需相關資訊,請參閱個別 CLI 命令的說明文件。 Here is a list of handy npm equivalents to get you started:

npm 命令pnpm 命令
npm installpnpm install
npm i <pkg>[pnpm add <pkg>]
npm run <cmd>[pnpm <cmd>]

When an unknown command is used, pnpm will search for a script with the given name, so pnpm run lint is the same as pnpm lint. If there is no script with the specified name, then pnpm will execute the command as a shell script, so you can do things like pnpm eslint (see pnpm exec).