Nodejs运行vue项目时,报错:Error: error:0308010C:digital envelope routines::unsupported
一、更改系统环境变量来解决
1、更改系统环境变量
①Windows平台
我的电脑上右键 → 属性 → 高级系统设置 → 添加系统变量: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 重新运行项目即可。