沙滩星空的博客沙滩星空的博客

node前端项目运行报错:Error: error:0308010C:digital envelope routines::unsupported

起因

重装操作系统后,运行一个 ant design 前端项目, 执行 yarn start 命令报错:

node:internal/crypto/hash:71
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
......
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

网上查资料得知,这是新 node v17 后,版本的问题。OpenSSL3.0对允许算法和密钥大小增加了严格的限制,可能会对生态系统造成一些影响。在node v17以前一些可以正常运行的的应用程序,但是在 V17 版本可能会抛出异常。

解决

解决办法:

添加 NODE_OPTIONS=--openssl-legacy-provider 环境变量

# windows 临时设置
set NODE_OPTIONS="--openssl-legacy-provider"
# windows 永久设置 (setx 命令保存环境变量到用户变量中。若要保存到系统变量中,请自行操作。)
setx NODE_OPTIONS --openssl-legacy-provider
# Linux
export NODE_OPTIONS=--openssl-legacy-provider

https://www.jianshu.com/p/58444afa75d6
https://blog.csdn.net/weixin_38883338/article/details/127699257

未经允许不得转载:沙滩星空的博客 » node前端项目运行报错:Error: error:0308010C:digital envelope routines::unsupported

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址