问题描述
启动项目npm start时遇到报错error:0308010C
this[kHandle] = new _Hash(algorithm, xofLen);
^
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:69:19)
at Object.createHash (node:crypto:133:10)
at BulkUpdateDecorator.hashFactory (D:\工作\ncmesw\changzhou-management\WEB\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\util\createHash.js:145:18)
at BulkUpdateDecorator.update (D:\工作\ncmesw\changzhou-management\WEB\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\util\createHash.js:46:50)
at RawSource.updateHash (D:\工作\ncmesw\changzhou-management\WEB\node_modules\@angular-devkit\build-angular\node_modules\webpack-sources\lib\RawSource.js:77:8)
at NormalModule._initBuildHash (D:\工作\ncmesw\changzhou-management\WEB\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\NormalModule.js:880:17)
at handleParseResult (D:\工作\ncmesw\changzhou-management\WEB\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\NormalModule.js:946:10)
at D:\工作\ncmesw\changzhou-management\WEB\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\NormalModule.js:1040:4
at processResult (D:\工作\ncmesw\changzhou-management\WEB\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\NormalModule.js:755:11)
at D:\工作\ncmesw\changzhou-management\WEB\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\NormalModule.js:819:5 {
opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'
}
Node.js v18.19.1
原因
出现这个错误是因为 node.js V17版本中最近发布的OpenSSL3.0, 而OpenSSL3.0对允许算法和密钥大小增加了严格的限制,可能会对生态系统造成一些影响.
解决办法
可以在配置中 运行和打包代码加上
--openssl-legacy-provider
如下 start 指令 和 prod指令"start": "node --openssl-legacy-provider -max-old-space-size=8048 ./node_modules/@angular/cli/bin/ng serve", "prod": "node --openssl-legacy-provider --max-old-space-size=8048 ./node_modules/@angular/cli/bin/ng build --configuration production --build-optimizer"