当前位置: 首页 > article >正文

解决启动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。


http://www.kler.cn/a/584978.html

相关文章:

  • 深入理解pytest框架中的conftest.py:使用与作用原理
  • 爬取数据时如何处理可能出现的异常?
  • 系统开发资源
  • Qt 实现透明可移动悬浮工具条
  • c#面试题整理10
  • 纽扣电池缺陷分割数据集labelme格式28张2类别
  • 阶乘之和(信息学奥赛一本通-2033)
  • 【互联网性能指标】QPS/TPS/PV/UV/IP/GMV/DAU/MAU/RPS
  • Linux第七讲:基础IO
  • 记忆 `lower_bound` 和 `upper_bound`(或你实现的 `last_less_equal`)
  • 基于springboot vue前后端分离的网上书城
  • 单一责任原则在Java设计模式中的深度解析
  • 失踪人口回归之Java开发工程师面试记录第一篇
  • 接口正常被调用且返回数据但前端页面渲染失败,控制台报错Uncaught (in promise)
  • react对比vue的核心属性
  • 【水文模型】地理信息系统(ArcGIS)在水文水资源、水环境中的应用
  • VBA即用型代码手册:选择、转到Select、 Go To
  • 【Python】Linux 升级 Python 版本(源码安装)
  • 地理信息系统(ArcGIS)在水文水资源及水环境中的应用:空间数据管理‌、空间分析功能‌、‌可视化表达‌
  • 【后端】【django drf】Django DRF API 编写规范(程序设计规则)