记录一次Node升级之后,引发老项目无法启动的问题。ERR_OSSL_EVP_UNSUPPORTED

2023-02-17 15:21:13 浏览数 (1)

问题记录

今天把一个以前的古早项目拖出来,准备跑起来改一改。

代码语言:javascript复制
# 安装npm包
yarn i - D
# 运行
yarn run serve

一番操作下来,如行云流水。结果报错了:

代码语言:javascript复制
 opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'

只好求助万能的百度(谷歌),关键词“ERR_OSSL_EVP_UNSUPPORTED”,最终得到如下结论:

If you hit an ERR_OSSL_EVP_UNSUPPORTED error in your application with Node.js 17, it’s likely that your application or a module you’re using is attempting to use an algorithm or key size which is no longer allowed by default with OpenSSL 3.0. A new command-line option, --openssl-legacy-provider, has been added to revert to the legacy provider as a temporary workaround for these tightened restrictions.

添加node运行选项 --openssl-legacy-provider,可以解决这个报错的问题。

Node更新日志

https://medium.com/the-node-js-collection/node-js-17-is-here-8dba1e14e382

问题解决

问题的原因和解决方法都有了,剩下的就是实际操作了。

打开node_modules/.bin,找到构建工具的启动命令,在node的后面加上启动参数,然后保存。

代码语言:javascript复制
node --openssl-legacy-provider  "$basedir/../@vue/cli-service/bin/vue-cli-service.js" "$@"

也可以选择修改环境变量来设置node的option:

代码语言:javascript复制
NODE_OPTIONS="--openssl-legacy-provider"

yarn run serve,正常运行,大功告成!

0 人点赞