pnpm安装报错 pnpm : The term ‘pnpm‘ is not recognized as the name of a cmdlet, function,script file

windows10

问题 安装pnpm失败

> pnpm install
pnpm : The term 'pnpm' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, 
or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ pnpm install
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (pnpm:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

解决步骤

安装node和npm并配置环境 --> 用npm安装pnpm (此时出现Bug) --> 修改cmd执行策略 -->成功

一、前提要有安装node和npm并配置好环境【已安装请直接跳过】

官网:下载 | Node.js 中文网 (nodejs.cn)

1.下载完检查版本
PS C:\Users\zal> node -v
v20.15.0
PS C:\Users\zal> npm -v
10.7.0

2.手动添加node_global和node_global文件夹并添加配置(完成2/3) 
npm config set prefix "D:exes\nodejs\node_global"
npm config set cache "D:\exes\nodejs\node_cache"

这里发现淘宝镜像源过期 所以多一步清除缓存重新设置

3.清除npm缓存
npm cache clean --force
清除pnpm缓存
pnpm store prune


4.配置镜像站提速(完成3/3)
npm config set registry https://registry.npmmirror.com

3个配置设定完后检查

PS C:\Users\zal> npm config list
; "builtin" config from D:\exes\nodejs\node_modules\npm\npmrc

; prefix = "C:\\Users\\zal\\AppData\\Roaming\\npm" ; overridden by user

; "user" config from C:\Users\zal\.npmrc

cache = "D:\\exes\\nodejs\\node_cache"
prefix = "D:\\exes\\nodejs\\node_global"
registry = "https://registry.npmmirror.com"

; node bin location = D:\exes\nodejs\node.exe
; node version = v20.15.0
; npm local prefix = C:\Users\zal
; npm version = 10.7.0
; cwd = C:\Users\zal
; HOME = C:\Users\zal
; Run `npm config ls -l` to show all defaults.

打开设置里的环境配置
系统环境变量

新建NODE_PATH设置D:\exes\nodejs\node_modules
编辑PATH新增%NODE_PATH%

用户环境变量

编辑PATH把【C:\Users\zal\AppData\Roaming\npm】编辑为【D:\exes\nodejs\node_global】

二、安装pnpm

//安装
PS C:\Users\zal> npm i -g pnpm

added 1 package in 2s

1 package is looking for funding
  run `npm fund` for details

//检查 报错
pnpm -v

报错两种
1. The term 'pnpm' is not recognized as the name of a cmdlet, function, script file
2.File D:\exes\nodejs\node_global\pnpm.ps1 cannot be loaded because running scripts is disabled on this system. Fo r more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.


三、修改cmd执行策略

这里找了很多方法最后发现是需要更换策略

获取策略。如果返回结果是:Restricted(受限)或AllSigned(所有脚本都必须经过签名)
你需要设置一个更宽松的策略为:RemoteSigned(本地脚本无限制,远程脚本必须经过签名)

PS C:\Users\zal> Get-ExecutionPolicy
Restricted
PS C:\Users\zal> Set-ExecutionPolicy RemoteSigned

成功了!

PS C:\Users\zal> pnpm -v
9.5.0
  • 17
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值