nodejs 启动报错问题
升级了node.js 版本到 v17.9.1,出现如下错误:
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:67:19)
at Object.createHash (node:crypto:135:10)
at module.exports (H:\iWork\产品代码\前端代码\ui_1\node_modules\webpack\lib\util\createHash.js:135:53)
at NormalModule._initBuildHash (H:\iWork\产品代码\前端代码\ui_1\node_modules\webpack\lib\NormalModule.js:417:16)
at handleParseError (H:\iWork\产品代码\前端代码\ui_1\node_modules\webpack\lib\NormalModule.js:471:10)
at H:\iWork\产品代码\前端代码\ui_1\node_modules\webpack\lib\NormalModule.js:503:5
at H:\iWork\产品代码\前端代码\ui_1\node_modules\webpack\lib\NormalModule.js:358:12
at H:\iWork\产品代码\前端代码\ui_1\node_modules\loader-runner\lib\LoaderRunner.js:373:3
at Storage.finished (H:\iWork\产品代码\前端代码\ui_1\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
at H:\iWork\产品代码\前端代码\ui_1\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
at H:\iWork\产品代码\前端代码\ui_1\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’ ],
library: ‘digital envelope routines’,
reason: ‘unsupported’,
code: ‘ERR_OSSL_EVP_UNSUPPORTED’
解决方法
$env:NODE_OPTIONS=”–openssl-legacy-provider”
或
set NODE_OPTIONS=–openssl-legacy-provider
补充:
在终端输入一次只能本次生效,如果想永久生效可以在 package.json 文件中修改对应的 scripts 节点的内容如下:
“serve”: “SET NODE_OPTIONS=–openssl-legacy-provider && vue-cli-service serve”,
“build”: “SET NODE_OPTIONS=–openssl-legacy-provider && vue-cli-service build”
或者在windows配置环境变量
Windows系统:添加变量名为NODE_OPTIONS变量值为–openssl-legacy-provider的环境变量