vue执行npm run dev报错如下
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:69:19)
at Object.createHash (node:crypto:133:10)
at module.exports (F:\ray\taisheng-erp-frontend-master\node_modules\webpack\lib\util\createHash.js:135:53)
at NormalModule._initBuildHash (F:\ray\taisheng-erp-frontend-master\node_modules\webpack\lib\NormalModule.js:417:16)
at handleParseError (F:\ray\taisheng-erp-frontend-master\node_modules\webpack\lib\NormalModule.js:471:10)
at F:\ray\taisheng-erp-frontend-master\node_modules\webpack\lib\NormalModule.js:503:5
at F:\ray\taisheng-erp-frontend-master\node_modules\webpack\lib\NormalModule.js:358:12
at F:\ray\taisheng-erp-frontend-master\node_modules\loader-runner\lib\LoaderRunner.js:373:3
at iterateNormalLoaders (F:\ray\taisheng-erp-frontend-master\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
at Array.<anonymous> (F:\ray\taisheng-erp-frontend-master\node_modules\loader-runner\lib\LoaderRunner.js:205:4)
at Storage.finished (F:\ray\taisheng-erp-frontend-master\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
at F:\ray\taisheng-erp-frontend-master\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
at F:\ray\taisheng-erp-frontend-master\node_modules\graceful-fs\graceful-fs.js:123:16
at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
原因
nodeJs V17版本发布了OpenSSL3.0对算法和秘钥大小增加了更为严格的限制,导致了nodeJs V17之前版本不受影刺而nodeJs V17和之后的版本会出现这个错误。
也就是npm升级导致了与OpenSSL不兼容导致的初始化失败,也就是nodeJs版本过高的原因导致了运行失败。
查看安装的nodejs版本
npm version
openssl: '3.0.10+quic',
node: '18.18.1',
可以看到本人使用的nodejs版本和OpenSSL版本
解决方法
1、修改系统环境变量
增加NODE_OPTIONS=–openssl-legacy-provider
2、修改项目环境变量
在package.json的scripts增加:set NODE_OPTIONS=–openssl-legacy-provider
如下所示
"scripts": {
"dev": "set NODE_OPTIONS=--openssl-legacy-provider & vue-cli-service serve --open",
"build": "vue-cli-service build",
"docker": "vue-cli-service build --mode docker",
"test": "vue-cli-service build --mode test",
"build:all": "npm run build && npm run test",
"lint": "eslint --ext .js,.vue src"
},
然后再执行npm run dev即可