1. Node起服务失败,报错如下:
node:internal/crypto/hash:69
this[kHandle] = new _Hash(algorithm, xofLen);
^
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:69:19)
at Object.createHash (node:crypto:133:10)
at BulkUpdateDecorator.hashFactory (/Users/houlei01/workspace/iwork-admin-2/apps/iwork/iwork-admin/node_modules/.pnpm/@umijs+deps@3.5.41/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:184161:18)
at BulkUpdateDecorator.update (/Users/houlei01/workspace/iwork-admin-2/apps/iwork/iwork-admin/node_modules/.pnpm/@umijs+deps@3.5.41/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:184062:50)
at /Users/houlei01/workspace/iwork-admin-2/apps/iwork/iwork-admin/node_modules/.pnpm/@umijs+deps@3.5.41/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:107101:9
at /Users/houlei01/workspace/iwork-admin-2/apps/iwork/iwork-admin/node_modules/.pnpm/@umijs+deps@3.5.41/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:33829:16
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.js v18.19.1
原因分析:
从报错信息可以看到:
Error: error:0308010C:digital envelope routines::unsupported
表示 Node.js 尝试使用旧的加密算法,而 OpenSSL v3 默认不再支持这些不安全的加密方法。
这是由于 Node.js 18.x 版本中的 OpenSSL v3 对旧加密算法的支持发生了变化,导致一些使用旧版加密方法的库无法正常工作。
解决方案
方案 1: 设置环境变量 (推荐)
在终端执行以下命令,强制启用旧版加密算法:
export NODE_OPTIONS=--openssl-legacy-provider
或者直接在命令前加:
NODE_OPTIONS=--openssl-legacy-provider your-command
比如:
NODE_OPTIONS=--openssl-legacy-provider npm run start
方案 2: 降级 Node.js 版本
如果项目对 Node.js 18 没有强制要求,可以降级到 Node.js 16.x 版本。
安装 Node.js 16:
nvm install 16
nvm use 16