共计 944 个字符,预计需要花费 3 分钟才能阅读完成。
问题记录
今天把一个以前的古早项目拖出来,准备跑起来改一改。
# 安装 npm 包
yarn i - D
# 运行
yarn run serve
一番操作下来,如行云流水。结果报错了:
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_modules/.bin,找到构建工具的启动命令,在 node 的后面加上启动参数,然后保存。
node --openssl-legacy-provider "$basedir/../@vue/cli-service/bin/vue-cli-service.js" "$@"
也可以选择修改环境变量来设置 node 的 option:
NODE_OPTIONS="--openssl-legacy-provider"
yarn run serve,正常运行,大功告成!