报错内容:
error:0308010C:digital envelope routines::unsupportedat new Hash (node:internal/crypto/hash:71:19)at Object.createHash (node:crypto:133:10)……this[kHandle] = new _Hash(algorithm, xofLen);^Error: error:0308010C:digital envelope routines::unsupportedat new Hash (node:internal/crypto/hash:71:19)at Object.createHash (node:crypto:133:10)……opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],library: 'digital envelope routines',reason: 'unsupported',code: 'ERR_OSSL_EVP_UNSUPPORTED'
}
报错原因:
Node.js v17版本中发布了 OpenSSL 3.0,对算法和秘钥大小增加了更为严格的限制, 在3.0版本中 md4不再被允许使用,在node 17版本之前使用 md4方法不会报错,
但 v17之后将抛出一个 error code 为 ERR_OSSL_EVP_UNSUPPORTED 的错误信息。
解决方式1:
在package.json的scripts中新增SET NODE_OPTIONS=–openssl-legacy-provider
修改前:
"scripts": {"serve": "vue-cli-service serve","build": "vue-cli-service build","lint": "vue-cli-service lint"}
修改后:
"scripts": {"serve": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve","build": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build","lint": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service lint"}
SET NODE_OPTIONS=–openssl-legacy-provider意思就是别使用OpenSSL 3.0,还使用老版的 OpenSSL。
解决方式2:
安装node17以下版本,建议使用nvm来管理不同版本的node
https://blog.csdn.net/qq_39460057/article/details/129322588?spm=1001.2014.3001.5501