pnpm包管理器的配置
规范管理全局包 / 缓存
1.手动新建E:\software\node_global 和 E:\software\node_cache
2.在E盘下执行
npm config set prefix "E:\software\node_global"
npm config set cache "E:\software\node_cache"
3.重启终端,在E盘下执行:npm i pnpm -g,整个系统可用
遇到问题
Microsoft Windows [版本 10.0.26200.7840]
(c) Microsoft Corporation。保留所有权利。
E:\>npm i pnpm -g
npm error code EPERM
npm error syscall mkdir
npm error path E:\software\node_cache\_cacache
npm error errno EPERM
npm error FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/pnpm: EPERM: operation not permitted, mkdir 'E:\software\node_cache\_cacache'
npm error at E:\software\nodejs\node_modules\npm\node_modules\minipass-fetch\lib\body.js:170:15
npm error at async Response.json (E:\software\nodejs\node_modules\npm\node_modules\minipass-fetch\lib\body.js:75:17)
npm error at async RegistryFetcher.packument (E:\software\nodejs\node_modules\npm\node_modules\pacote\lib\registry.js:98:25)
npm error at async RegistryFetcher.manifest (E:\software\nodejs\node_modules\npm\node_modules\pacote\lib\registry.js:128:23)
npm error at async #fetchManifest (E:\software\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1202:20)
npm error at async #nodeFromEdge (E:\software\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1040:19)
npm error at async #buildDepStep (E:\software\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:904:11)
npm error at async Arborist.buildIdealTree (E:\software\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:181:7)
npm error at async Arborist.reify (E:\software\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:131:5)
npm error at async Install.exec (E:\software\nodejs\node_modules\npm\lib\commands\install.js:150:5) {
npm error code: 'EPERM',
npm error errno: 'EPERM',
npm error syscall: 'mkdir',
npm error path: 'E:\\software\\node_cache\\_cacache',
npm error type: 'system',
npm error requiredBy: '.'
npm error }
npm error
npm error The operation was rejected by your operating system.
npm error It's possible that the file was already in use (by a text editor or antivirus),
npm error or that you lack permissions to access it.
npm error
npm error If you believe this might be a permissions issue, please double-check the
npm error permissions of the file and its containing directories, or try running
npm error the command again as root/Administrator.
npm error Log files were not written due to an error writing to the directory: E:\software\node_cache\_logs
npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
原因:遇到的 EPERM 错误是权限问题—— 系统禁止 npm 在 E:\software\node_cache 目录下创建文件夹,这是 Windows 很常见的权限报错
解决
win+r以管理员身份运行终端
PS C:\Users\吴旭烨> E:
PS E:\> npm i pnpm -g
changed 1 package in 14s
1 package is looking for funding
run `npm fund` for details
但是在pnom -v的时候出错
PS E:\> pnpm -v
pnpm : 无法将“pnpm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确
,然后再试一次。
所在位置 行:1 字符: 1
+ pnpm -v
+ ~~~~
+ CategoryInfo : ObjectNotFound: (pnpm:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
解决
右键「此电脑」→「属性」→「高级系统设置」→「环境变量」(或者win+r键入:sysdm.cpl);
在「用户变量」的 Path 里,确认 E:\software\node_global 已经存在(没有的话自己添加);
如果存在但仍报错,把 E:\software\node_global 「上移」到 Path 列表的最顶部(提升优先级);
点击「确定」保存,后续新开终端就会自动识别 pnpm 了。
结果
Microsoft Windows [版本 10.0.26200.7840]
(c) Microsoft Corporation。保留所有权利。
C:\Users\aitty>pnpm -v
10.30.3
C:\Users\aitty>E:
E:\>pnpm -v
10.30.3

浙公网安备 33010602011771号