pnpm简介
pnpm( performant npm )是一个同npm、yarn类似的前端node_module包管理工具,其初衷是节约磁盘空间并提升安装速度。
pnpm 优势
软链接优化依赖管理
官网地址:pnpm官网
命令对比
npm | yarn | pnpm |
---|---|---|
npm install | yarn | pnpm install |
npm install 包名 | yarn add 包名 | pnpm add 包名 |
npm uninstall 包名 | yarn remove 包名 | pnpm remove 包名 |
npm run 脚本 | yarn 脚本 | pnpm 脚本 |
安装
通过 npm 安装
npm install -g pnpm
通过HomeBrew 安装
这里我使用的是HomeBrew
1. 第一步 输入命令
brew install pnpm
代码如下,然后报错
runnumb@RundeMacBook-Pro nxin-code % brew install pnpm
fatal: not in a git directory
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-cask, skipping update!
fatal: not in a git directory
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-core, skipping update!
fatal: not in a git directory
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-services, skipping update!
==> Homebrew has enabled anonymous aggregate formula and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics have been recorded yet (nor will be during this `brew` run).
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/pnpm-7.17.1.arm64_ventura.bottle.tar.gz
curl: (22) The requested URL returned error: 404
Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/pnpm/manifests/7.17.1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/pnpm/blobs/sha256:4315d45611ecd4410d2dda95beb0148133fc4529a5282811665598ccdf1dfd09
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:4315d45611ecd4410d2dda95beb0148133fc4529a5282811665598ccdf1dfd09?se=2023-01-31T03%3A05%3A
######################################################################## 100.0%
fatal: not in a git directory
Error: Command failed with exit 128: git
解决办法:
brew -v 查看会有两个提示,提示用户设置 homebrew-cask 和 homebrew-core 的文件路径为设置为safe.directory
runnumb@RundeMacBook-Pro nxin-code % brew -v
Homebrew 3.6.12-20-g9c88c39
fatal: detected dubious ownership in repository at '/opt/homebrew/Library/Taps/homebrew/homebrew-core'
To add an exception for this directory, call:
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core (no Git repository)
fatal: detected dubious ownership in repository at '/opt/homebrew/Library/Taps/homebrew/homebrew-cask'
To add an exception for this directory, call:
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask (no Git repository)
2.这时按照终端给的提示吗,分别使用两个命令,如下
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
示例如下:
runnumb@RundeMacBook-Pro nxin-code % git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
runnumb@RundeMacBook-Pro nxin-code % git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
runnumb@RundeMacBook-Pro nxin-code % brew -v
Homebrew 3.6.12-20-g9c88c39
Homebrew/homebrew-core (git revision 4cdce4bfdd2; last commit 2022-11-29)
Homebrew/homebrew-cask (git revision 11c175be64; last commit 2022-11-29)
3. 然后再执行:
arch -arm64 brew install cocoapods
示例如下:
runnumb@RundeMacBook-Pro nxin-code % arch -arm64 brew install cocoapods
fatal: not in a git directory
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-services, skipping update!
Warning: Treating cocoapods as a formula. For the cask, use homebrew/cask/cocoapods
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/libyaml-0.2.5.arm64_ventura.bottle.tar.gz
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/ca-certificates-2022-10-11.all.bottle.tar.gz
curl: (22) The requested URL returned error: 404
Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/manifests/2022-10-11
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/blobs/sha256:1b264e579e31b3041a87ff91f09d5f7cc0d51fea1c83e63aee17a1b95509cbe1
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:1b264e579e31b3041a87ff91f09d5f7cc0d51fea1c83e63aee17a1b95509cbe1?se=2023-01-31T03%3A10%3A
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/openssl%401.1-1.1.1s.arm64_ventura.bottle.tar.gz
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/readline-8.2.1.arm64_ventura.bottle.tar.gz
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/ruby-3.1.2_1.arm64_ventura.bottle.1.tar.gz
curl: (22) The requested URL returned error: 404
Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/manifests/3.1.2_1-1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/blobs/sha256:75974aaea5681d1d141f12625c15c19e0e0324ade9a5bbe37945c7b4a7323c58
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:75974aaea5681d1d141f12625c15c19e0e0324ade9a5bbe37945c7b4a7323c58?se=2023-01-31T03%3A10%3A
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/cocoapods-1.11.3.arm64_ventura.bottle.tar.gz
curl: (22) The requested URL returned error: 404
Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/cocoapods/manifests/1.11.3
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/cocoapods/blobs/sha256:d7a566fdc19b54792dfb58a70126d9a847fbdcc4eb4fd0c3c402cc143fcdf704
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:d7a566fdc19b54792dfb58a70126d9a847fbdcc4eb4fd0c3c402cc143fcdf704?se=2023-01-31T03%3A25%3A
######################################################################## 100.0%
==> Installing dependencies for cocoapods: libyaml, ca-certificates, openssl@1.1, readline and ruby
==> Installing cocoapods dependency: libyaml
==> Pouring libyaml-0.2.5.arm64_ventura.bottle.tar.gz
🍺 /opt/homebrew/Cellar/libyaml/0.2.5: 10 files, 351.2KB
==> Installing cocoapods dependency: ca-certificates
==> Pouring ca-certificates-2022-10-11.all.bottle.tar.gz
Error: No such file or directory @ rb_sysopen - /Users/runnumb/Library/Caches/Homebrew/downloads/45aa6cd2270164620e943b04684f2aab7fc067bf491eef09870797858dfc7679--ca-certificates-2022-10-11.all.bottle.tar.gz
4. 最后再次执行
brew install pnpm
示例如下:
runnumb@RundeMacBook-Pro nxin-code % brew install pnpm
fatal: not in a git directory
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-services, skipping update!
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/pnpm-7.17.1.arm64_ventura.bottle.tar.gz
curl: (22) The requested URL returned error: 404
Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/pnpm/manifests/7.17.1
Already downloaded: /Users/runnumb/Library/Caches/Homebrew/downloads/b220af0f800bc33ba56eb10795f2f6922a466b972ddc4b12570fb27b155331cc--pnpm-7.17.1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/pnpm/blobs/sha256:4315d45611ecd4410d2dda95beb0148133fc4529a5282811665598ccdf1dfd09
Already downloaded: /Users/runnumb/Library/Caches/Homebrew/downloads/8f772b16919f8a48871542061254827ac4ef30536704e9c96c6c6b14d3bd77dc--pnpm--7.17.1.arm64_ventura.bottle.tar.gz
==> Pouring pnpm--7.17.1.arm64_ventura.bottle.tar.gz
==> Caveats
pnpm requires a Node installation to function. You can install one with:
brew install node
==> Summary
🍺 /opt/homebrew/Cellar/pnpm/7.17.1: 659 files, 12.0MB
==> Running `brew cleanup pnpm`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
最后安装成功 pnpm -v
查看版本即可
参考资料:https://blog.csdn.net/Morris_/article/details/125182905