常见安装 Vue 报错解决方法
安装 Vue 报错解决
报错:
C:\Users\21877>npm install -g cnpm --registry=https://registry.npm.taobao.org
npm error code CERT_HAS_EXPIRED
npm error errno CERT_HAS_EXPIRED
npm error request to https://registry.npm.taobao.org/cnpm failed, reason: certificate has expired
npm error A complete log of this run can be found in: D:\nodejs\node_cache\_logs\2025-09-04T01_33_52_400Z-debug-0.log
解决方案:
跳过旧域名,直接用新域名安装:
npm install -g cnpm --registry=https://registry.npmmirror.com
然后再安装:
npm install -g cnpm
又报错:
C:\Users\21877>npm install -g cnpm --registry=https://registry.npmmirror.comadded 1 package in 14sC:\Users\21877>npm install -g cnpm
npm error code CERT_HAS_EXPIRED
npm error errno CERT_HAS_EXPIRED
npm error request to https://registry.npm.taobao.org/cnpm failed, reason: certificate has expired
npm error A complete log of this run can be found in: D:\nodejs\node_cache\_logs\2025-09-04T01_37_20_989Z-debug-0.log
报错原因:npm 配置仍指向旧镜像:
第一次安装时指定了新镜像源(--registry=https://registry.npmmirror.com
)并成功安装,但第二次直接运行 npm install -g cnpm
时,npm 可能仍使用配置中旧的镜像源(https://registry.npm.taobao.org
)来下载包。
解决方案:
永久更换 npm 镜像源到新地址
运行以下命令,将 npm 的默认镜像源设置为新地址:
npm config set registry https://registry.npmmirror.com
之后,再安装 cnpm 或其它包时就会默认使用新镜像源:
npm install -g cnpm
验证是否修改成功:
npm config get registry
如果输出 https://registry.npmmirror.com
,说明配置成功 。