解决启动Vue项目时遇到的 error:0308010C:digital envelope routines::unsupported 错误

问题描述

最近,在启动一个遗留前端(Vue)项目时,遇到了error:0308010C:digital envelope routines::unsupported错误。

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:79:19)
    at Object.createHash (node:crypto:139:10)
    at D:\code\front\shucheng-admin-ui\node_modules\compression-webpack-plugin\dist\index.js:243:42    
    at CompressionPlugin.compress (D:\code\front\shucheng-admin-ui\node_modules\compression-webpack-plugin\dist\index.js:284:9)
    at D:\code\front\shucheng-admin-ui\node_modules\compression-webpack-plugin\dist\index.js:305:12    
    at _next1 (eval at create (D:\code\front\shucheng-admin-ui\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:14:17)
    at eval (eval at create (D:\code\front\shucheng-admin-ui\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:33:1)
    at D:\code\front\shucheng-admin-ui\node_modules\copy-webpack-plugin\dist\index.js:91:9

这是因为Node.js v17 及以上版本默认使用 OpenSSL 3.x,而 OpenSSL 3.x 移除了对一些旧加密算法的支持。因此,依赖这些旧算法的模块(如CompressionPlugin)在运行时可能会抛出 error:0308010C:digital envelope routines::unsupported 错误。

解决方案(TL;DR)

方案一:使用 OpenSSL 旧版提供程序

通过在启动命令中设置 NODE_OPTIONS=--openssl-legacy-provider,强制 Node.js 使用旧版的 OpenSSL 提供程序,从而支持被移除的旧算法。

具体操作
Windows 系统:

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

Unix/Linux/Mac 系统:

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

方案二:降级 Node.js 版本

如果您不需要 Node.js v17 及以上版本的新功能,可以考虑降级到 Node.js v16 或更早的版本。这些版本默认使用 OpenSSL 1.x,通常不会遇到该问题。

方案三:更新相关依赖

检查是否有更新版本的 CompressionPlugin 或其他依赖库,新版本可能已经兼容 OpenSSL 3.x。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Honyelchak

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值