前言
更新 NodeJS 到 V17 後,執行 npx webpack
時,會噴 error:0308010C:digital envelope routines::unsupported
的錯誤
node_modules\loader-runner\lib\LoaderRunner.js:133
if(isError) throw e;
^
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:67:19)
at Object.createHash (node:crypto:130:10)
at module.exports (C:\Projects\local_directline\node_modules\webpack\lib\util\createHash.js:135:53)
at NormalModule._initBuildHash (C:\Projects\local_directline\node_modules\webpack\lib\NormalModule.js:417:16)
at handleParseError (C:\Projects\local_directline\node_modules\webpack\lib\NormalModule.js:471:10)
…
opensslErrorStack: [ ‘error:03000086:digital envelope routines::initialization error’ ],
library: ‘digital envelope routines’,
reason: ‘unsupported’,
code: ‘ERR_OSSL_EVP_UNSUPPORTED’
解法
專案中使用的 webpack 版本是 4.19 ,參考 webpack: Avoid md4 hash for OpenSSL 3 compatibility 的解法,將 hash 設定成 sha256。
所以在 webpack.config.js 中加入設定 hash 的程式碼,
1 | const crypto = require("crypto"); |
參考資訊
Webpack build failing with ERR_OSSL_EVP_UNSUPPORTED
webpack: Avoid md4 hash for OpenSSL 3 compatibility