解决 nodejs 17: digital envelope routines::unsupported

前端笔记 2022-01-06 10213℃ 0 12

更新 XMLiving 的主题发现无法构建 JS/CSS,报如下错误

PS E:\WorkSpace\development\wwwroot\usr\themes\XMLiving> npm run build                      

> xmliving@2.1.0 build
> webpack --config ./webpack/webpack.build.js

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:130:10)
    at BulkUpdateDecorator.hashFactory (E:\WorkSpace\development\wwwroot\usr\themes\XMLiving\node_modules\webpack\lib\util\createHash.js:145:18)
    at BulkUpdateDecorator.update (E:\WorkSpace\development\wwwroot\usr\themes\XMLiving\node_modules\webpack\lib\util\createHash.js:46:50)
    at OriginalSource.updateHash (E:\WorkSpace\development\wwwroot\usr\themes\XMLiving\node_modules\webpack\node_modules\webpack-sources\lib\OriginalSource.js:104:8)
    at NormalModule._initBuildHash (E:\WorkSpace\development\wwwroot\usr\themes\XMLiving\node_modules\webpack\lib\NormalModule.js:868:17)
    at handleParseResult (E:\WorkSpace\development\wwwroot\usr\themes\XMLiving\node_modules\webpack\lib\NormalModule.js:934:10)
    at E:\WorkSpace\development\wwwroot\usr\themes\XMLiving\node_modules\webpack\lib\NormalModule.js:1026:4
    at processResult (E:\WorkSpace\development\wwwroot\usr\themes\XMLiving\node_modules\webpack\lib\NormalModule.js:743:11)
    at E:\WorkSpace\development\wwwroot\usr\themes\XMLiving\node_modules\webpack\lib\NormalModule.js:807:5

Google 了一下发现是 Node JS 17 的 BUG,相关 ISSUE 也给出了解决办法,就是修改package.json,在相关构建命令之前加入set NODE_OPTIONS=--openssl-legacy-provider

"build": "set NODE_OPTIONS=--openssl-legacy-provider & webpack --config ./webpack/webpack.build.js",

如果是 Linux 或者 WSL 环境,请加入

export NODE_OPTIONS=--openssl-legacy-provider

评论 (0)

Top