npm启动前端项目时报错(vue) error:0308010C:digital envelope routines::unsupported

vue 启动项目时,npm run serve 报下面的错:

error:0308010C:digital envelope routines::unsupported

at new Hash (node:internal/crypto/hash:67:19)

at Object.createHash (node:crypto:133:10)

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'

}

D:\OpenSource\bpm-platform-ui-250115>npm run dev

> work-flowable@0.8.3 dev

> 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:79:19)

at Object.createHash (node:crypto:139:10)

at D:\OpenSource\bpm-platform-ui-250115\node_modules\compression-webpack-plugin\dist\index.js:243:42

at CompressionPlugin.compress (D:\OpenSource\bpm-platform-ui-250115\node_modules\compression-webpack-plugin\dist\index.js:284:9)

at D:\OpenSource\bpm-platform-ui-250115\node_modules\compression-webpack-plugin\dist\index.js:305:12

at _next1 (eval at create (D:\OpenSource\bpm-platform-ui-250115\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:14:17)

at eval (eval at create (D:\OpenSource\bpm-platform-ui-250115\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:33:1)

at D:\OpenSource\bpm-platform-ui-250115\node_modules\copy-webpack-plugin\dist\index.js:91:9

解决方法:

在窗口运行如下代码(修改环境变量),回车后重启即可~~~~

复制代码
$env:NODE_OPTIONS="--openssl-legacy-provider"

前端项目使用( npm run dev ) 运行vue项目时,出现错误:Error: error:0308010C:digital envelope routines::unsupported

经过探索,发现问题所在,主要是nodeJs V17版本发布了OpenSSL3.0对算法和秘钥大小增加了更为严格的限制,导致了nodeJs V17之前版本不受影刺而nodeJs V17和之后的版本会出现这个错误。

也就是npm升级导致了与OpenSSL不兼容导致的初始化失败,也就是nodeJs版本过高的原因导致了运行失败。

系统安装的nodeJs版本正好是V18,因此出现了这个错误系统。

解决方案

1、更改系统环境变量来解决

2、更改项目环境变量来解决

3、更换NodeJs版本来解决

具体演示

1、更改系统环境变量

①Windows平台

我的电脑上右键 → 属性 → 高级系统设置 → 添加系统变量:NODE_OPTIONS = --openssl-legacy-provider

②Linux / Mac 平台

export NODE_OPTIONS=--openssl-legacy-provider

完成后,建议重新打开一个命令行窗口启动服务。

2、更改项目环境变量来解决

①在 package.json 的 scripts 中新增:SET NODE_OPTIONS=--openssl-legacy-provider

添加前代码:

"scripts": {

"dev": "vue-cli-service serve",

"build:prod": "vue-cli-service build",

"build:stage": "vue-cli-service build --mode staging",

"preview": "node build/index.js --preview",

"lint": "eslint --ext .js,.vue src",

"test:unit": "jest --clearCache && vue-cli-service test:unit",

"test:ci": "npm run lint && npm run test:unit",

"svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml"

},

添加后代码:

"scripts": {

"dev": "set NODE_OPTIONS=--openssl-legacy-provider & vue-cli-service serve",

"build:prod": "vue-cli-service build",

"build:stage": "vue-cli-service build --mode staging",

"preview": "node build/index.js --preview",

"lint": "eslint --ext .js,.vue src",

"test:unit": "jest --clearCache && vue-cli-service test:unit",

"test:ci": "npm run lint && npm run test:unit",

"svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml"

},

这里需要注意的是,要是团队中的nodejs版本不一致,不要提交该 package.json 文件。

②与①类似,在编辑器集成终端里,直接设置环境变量进行控制(这种方式只能临时解决)

具体如下:

找到 package.json 文件右键,在集成终端中打开,直接输入 set NODE_OPTIONS=--openssl-legacy-provider 回车,然后 npm run serve 重新运行项目即可。

// windows系统

set NODE_OPTIONS=--openssl-legacy-provider

// linux系统

export NODE_OPTIONS=--openssl-legacy-provider

3、更换NodeJs版本来解决

卸载本地NodeJs环境,暗转NodeJsV17之前的版本。

相关推荐
萧行之7 分钟前
Ubuntu Node.js 版本管理工具 n 完整安装与使用教程
linux·前端
星晨雪海7 分钟前
企业标准 DTO 传参 + Controller + Service + 拷贝工具类完整版
java·开发语言·python
devlei7 小时前
从源码泄露看AI Agent未来:深度对比Claude Code原生实现与OpenClaw开源方案
android·前端·后端
pshdhx_albert7 小时前
AI agent实现打字机效果
java·http·ai编程
Jagger_8 小时前
周末和AI肝了两天,终于知道:为什么要把AI当做实习生
前端
weixin_456164838 小时前
vue3 子组件向父组件传参
前端·vue.js
沉鱼.448 小时前
第十二届题目
java·前端·算法
Setsuna_F_Seiei8 小时前
CocosCreator 游戏开发 - 多维度状态机架构设计与实现
前端·cocos creator·游戏开发
Bigger8 小时前
CodeWalkers:让 AI 助手化身桌面宠物,陪你敲代码的赛博伙伴!
前端·app·ai编程
赫瑞9 小时前
数据结构中的排列组合 —— Java实现
java·开发语言·数据结构