[Vue] [node.js] 报错:ERR_OSSL_EVP_UNSUPPORTED解决方法

Node8个月前更新 铁老班
0

现象

在Vue项目中,启动时报错ERR_OSSL_EVP_UNSUPPORTED。
具体报错内容:

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版本过高导致和以前的openssl版本不兼容。

解决方法

提供了两种解决方法,二选一。

1.设置环境变量
windows平台:
使用命令行输入如下命令:
set NODE_OPTIONS="--openssl-legacy-provider"

linux平台:
使用命令行输入如下命令:
export NODE_OPTIONs=--openssl-legacy-provider

2.修改Vue配置文件
在Vue的配置文件package.json中,在script中的serve和build命令中添加set NODE_OPTIONS=–openssl-legacy-provider语句:

"scripts": {
    "serve": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
    "build": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build",
    "lint": "vue-cli-service lint"
},
© 版权声明

相关文章