创建React项目时遭遇SELF_SIGNED_CERT_IN_CHAIN错误求助
React应用创建失败:SELF_SIGNED_CERT_IN_CHAIN错误
错误详情
PS C:\Users\Tashs November\Desktop\Event Management> npm create vite@lite
npm error code SELF_SIGNED_CERT_IN_CHAIN
npm error request to https://registry.npmjs.org/create-vite failed, reason: 证书链中存在自签名证书
npm error 本次运行的完整日志可查看:C:\Users\Tashs November\AppData\Local\npm-cache_logs\2024-07-31T08_45_49_900Z-debug-0.logPS C:\Users\Tashs November\Desktop\Event Management> npm create vite@latest
npm error code SELF_SIGNED_CERT_IN_CHAIN
npm error errno SELF_SIGNED_CERT_IN_CHAIN
已尝试的命令(均失败)
npm create vite@latestnpm create vite@litenpx create-react-app events management
解决方法
临时跳过证书校验(仅临时使用,不推荐生产环境)
执行命令关闭npm的严格证书校验:
npm config set strict-ssl false
完成应用创建后,建议重新开启校验:
npm config set strict-ssl true
配置代理信任证书(推荐网络环境受限场景)
若处于公司代理或内网环境,将代理根证书添加到npm信任列表:
- 获取代理提供的根证书文件(格式通常为
.crt或.pem) - 执行命令配置证书路径:
npm config set cafile "C:\你证书的完整路径\证书文件名.crt"
切换npm镜像源
如果上述方法无效,可尝试切换到国内镜像源:
npm config set registry https://registry.npmmirror.com/
设置完成后重新执行应用创建命令。
内容的提问来源于stack exchange,提问作者Ruvimbo November
相关产品推荐
相关产品推荐

