如何解决npm run serve运行vue项目时,出现报错:Error: error:0308010C:digital envelope routines::unsupported
2023-09-14 09:13:39 时间
❓ 问题描述
用npm run serve运行vue项目时,出现报错:Error: error:0308010C:digital envelope routines::unsupported
❌ 报错信息
前端项目启动(npm run dev)和打包时(npm run build:prod)报出如下错误,
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:71:19)
at Object.createHash (node:crypto:133:10)
at module.exports
....
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'
}
⁉️ 问题原因:
经过一番探索,终于找到了症结所在:主要是nodeJs V17版本发布了OpenSSL3.0对算法和秘钥大小增加了更为严格的限制,nodeJs v17之前版本没影响,但V17和之后版本会出现这个错误。
一句话总结,说白了就是npm升级导致与 openssl 不兼容导致的初始化失败,也就是node.js版本过高的原因造成的运行失败。
🎈 解决办法(仅windows):
◼️ 方式一:通过更改环境变量,进行控制
1、在package.json的scripts中新增SET NODE_OPTIONS=--openssl-legacy-provider
添加前:
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
添加后
"scripts": {
"serve": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
注意:如果团队中node版本不一致,不要将该package.json提交。
2、与第一种方法类似,在编辑器集成终端里,直接设置环境变量,进行控制(只能临时解决)
找到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
◼️ 方式二:更换node.js版本
相关文章
- Vue -> 解决 vue-ueditor-wrap 不能显示的问题
- VUE - 引入 npm 安装的模块 以及 uuid模块的使用
- 【记录】vue构建项目npm install错误run `npm audit fix` to fix them, or `npm audit` for details
- vue编程式路由实现新窗口打开
- This dependency was not found: * !!vue-style-loader!css-loader?……解决方案
- vue项目启动时将localhost替换成指定ip地址
- [NPM] Update published npm packages using np
- [NPM] Add comments to your npm scripts
- [NPM] Run a set of similar npm scripts with a wildcard
- vue父组件调用子组件资源
- vue.js3:用qrcode-parser解析二维码图片(vue@3.2.36 / qrcode-parser@2.0.4)
- npm ERR! Could not resolve dependency:npm ERR! peer vue@“^2.5.17“ from element-ui@2.15.12
- ASP.NET Core微服务(四)——【静态vue使用axios解析接口】
- vue中使用分页组件、将从数据库中查询出来的数据分页展示(前后端分离SpringBoot+Vue)
- Vue拖拽组件
- 214:vue+openlayers 加载geoserver数据,使用ImageWMS和ImageLayer呈现图形
- Vue(五)计算属性、过滤器、axios、vue 生命周期
- 【异常】Jenkins执行前端项目Npm构建时,出现报错This dependency was not found: vue-class-component in ./node_modules/vu
- Vue:第一个vue-cli项目