You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法通过npm安装任何包,遇ERR_OSSL_UNSUPPORTED错误求助

解决npm ERR_OSSL_UNSUPPORTED及过时配置警告问题

问题描述

我执行任何npm包安装命令(比如安装typescript)时,都会出现以下错误和警告:

npm WARN config key key and cert are no longer used for most registry operations.
npm WARN config Use registry scoped keyfile and certfile instead.
npm WARN config Example:
npm WARN config //other-registry.tld/:keyfile=/path/to/key.pem
npm WARN config //other-registry.tld/:certfile=/path/to/cert.crt
npm WARN config key key and cert are no longer used for most registry operations.
npm WARN config Use registry scoped keyfile and certfile instead.
npm WARN config Example:
npm WARN config //other-registry.tld/:keyfile=/path/to/key.pem
npm WARN config //other-registry.tld/:certfile=/path/to/cert.crt
npm ERR! code ERR_OSSL_UNSUPPORTED
npm ERR! error:1E08010C:DECODER routines::unsupported

解决方法

1. 修复ERR_OSSL_UNSUPPORTED错误

这个错误大多是Node.js使用的SSL版本不兼容或OpenSSL设置问题,可按以下方式解决:

  • 单命令临时修复:
    在执行npm安装时加上环境变量参数:
    NODE_OPTIONS=--openssl-legacy-provider npm install typescript
    
  • Windows永久修复:
    1. 打开「系统属性」→「高级」→「环境变量」
    2. 在「用户变量」里点击「新建」
    3. 变量名填NODE_OPTIONS,变量值填--openssl-legacy-provider
    4. 重启终端后再执行npm命令
  • macOS/Linux永久修复:
    把环境变量添加到shell配置文件(比如~/.bashrc或~/.zshrc):
    echo 'export NODE_OPTIONS="--openssl-legacy-provider"' >> ~/.zshrc
    # 如果是bash,就改成 echo 'export NODE_OPTIONS="--openssl-legacy-provider"' >> ~/.bashrc
    source ~/.zshrc
    

2. 消除过时配置警告

警告是因为npm配置里的key和cert参数已经过时,需要更新:

  • 先查看当前npm配置:
    npm config list
    
  • 删除旧的key和cert配置项:
    npm config delete key
    npm config delete cert
    
  • 如果需要给特定私有仓库配置证书,改用作用域的keyfile和certfile(替换成你的仓库地址和证书路径):
    npm config set //你的仓库域名/:keyfile=/证书文件路径/key.pem
    npm config set //你的仓库域名/:certfile=/证书文件路径/cert.crt
    

内容的提问来源于stack exchange,提问作者AKASH KUMAR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 07:52:41