当前位置: 首页>后端>正文

Vue项目:Error- error-0308010C-digital envelope routines--unsupported

背景

Vue2+ElementUI脚手架项目,启动的时候报下列错误

vue-cli-service serve

INFO Starting development server...
95% emitting CompressionPlugin ERROR Error: error:0308010C:digital envelope routines::unsupported
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:69:19)
at Object.createHash (node:crypto:133:10)

原因

第一感觉就是node版本的问题,因为本地node版本用的算是比较新的,用的18.8.2版本。经过查询相关资料,发现是node17以后OpenSSL3.0对允许算法和密钥大小增加了严格的限制,由此造成的影响。既然找到了问题解决办法无外乎使用低版本node版本和解决openssl的兼容问题

解决办法

方法1 安装node版本管理器 n,切换到低版本node运行此项目

npm install -g n

n 16.20.1 //安装node 16,此处可以安装自己想用的版本

n use 16.20.1

方法2 设置环境变量,规避openssl问题

1、临时环境变量的方式

// macos或者linux
export NODE_OPTIONS=--openssl-legacy-provider
//windows
set NODE_OPTIONS=--openssl-legacy-provider

2、在vue项目的package.json中配置

  "scripts": {
    "dev": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
    "build:prod": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build",
    "build:stage": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build --mode staging"
}

原文链接:https://blog.csdn.net/wjwei113/article/details/135607189


https://www.xamrdz.com/backend/39j1944766.html

相关文章: