From 6a916d060a89585e0304508ea74a9c8272e8069a Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 28 May 2023 20:29:51 +0200 Subject: [PATCH] Make our Webpack config compatible with Node 18+ Node 18 and newer switched to OpenSSL 3, which does not support the MD4 hash algorithm. Unfortunately, Webpack 4 hardcodes the use of MD4 at various places. This leaves us no other option than to monkey-patch node to transform calls to the MD4 hash to use SHA256. References: https://github.com/webpack/webpack/issues/14532 https://stackoverflow.com/questions/69394632/webpack-build-failing-with-err-ossl-evp-unsupported/69691525#69691525 Signed-off-by: David Mehren --- package.json | 2 +- webpack.common.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 934b61825..9b639fc6d 100644 --- a/package.json +++ b/package.json @@ -107,7 +107,7 @@ "xss": "^1.0.3" }, "engines": { - "node": "16.x" + "node": ">=16" }, "bugs": "https://github.com/hedgedoc/hedgedoc/issues", "keywords": [ diff --git a/webpack.common.js b/webpack.common.js index 7827955f3..60ff23d90 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -5,6 +5,13 @@ const CopyWebpackPlugin = require('copy-webpack-plugin') const MiniCssExtractPlugin = require('mini-css-extract-plugin') const { CleanWebpackPlugin } = require('clean-webpack-plugin') +// This monkey-patches node to use sha256 instead of md4 for crypto.createHash +// md4 is not available in node 18+ anymore, as that uses modern OpenSSL versions +// Inspired by https://stackoverflow.com/questions/69394632/webpack-build-failing-with-err-ossl-evp-unsupported/69691525#69691525 +const crypto = require('crypto') +const cryptoOrigCreateHash = crypto.createHash +crypto.createHash = algorithm => cryptoOrigCreateHash(algorithm === 'md4' ? 'sha256' : algorithm) + // Fix possible nofile-issues const fs = require('fs') const gracefulFs = require('graceful-fs')