Windows10中Yarn 1.5.1经npm卸载后仍无法升级该如何解决?
解决Windows 10下npm卸载Yarn后无法升级的问题
问题场景
Windows 10系统,当前Yarn版本为1.5.1,执行npm uninstall -g yarn后尝试升级Yarn,出现连接错误与空值读取错误。
执行命令及输出
卸载Yarn命令
npm uninstall -g yarn
输出:
removed 1 package, and audited 1 package in 18s found 0 vulnerabilities
升级Yarn命令
npm upgrade --global yarn
输出:
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/ npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/ npm ERR! Cannot read properties of null (reading 'pickAlgorithm') npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\qxz3xng\AppData\Local\npm-cache\_logs\2023-06-02T05_54_25_455Z-debug-0.log
问题分析
- 当前npm使用明文HTTP连接访问注册表,不符合要求的TLS 1.2及以上版本规范,导致连接受限
- 连接异常引发npm无法正常获取包信息,进而出现
Cannot read properties of null (reading 'pickAlgorithm')错误
解决步骤
切换npm注册表为HTTPS源
npm config set registry https://registry.npmjs.org/执行以下命令验证设置:
npm config get registry确认输出为
https://registry.npmjs.org/即可。清理npm缓存
npm cache clean --force彻底清理残留的Yarn文件(若卸载后仍能查到版本)
- 删除全局Yarn模块目录:
C:\Users\[你的用户名]\AppData\Roaming\npm\node_modules\yarn - 删除Yarn可执行文件:
C:\Users\[你的用户名]\AppData\Roaming\npm\yarn.cmd和yarnps.cmd
- 删除全局Yarn模块目录:
重新安装最新版Yarn
npm install -g yarn验证安装结果
yarn --version确认输出为最新版本即完成修复。
内容的提问来源于stack exchange,提问作者Jumper
相关产品推荐
相关产品推荐

