Fix error:0308010C:digital envelope routines::unsupported
webpack 4 on Node 22 or 24 failing with error:0308010C digital envelope routines::unsupported is the md4 hash. Upgrade to 4.47.0; legacy flag only briefly.
Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:101:19) at Object.createHash (node:crypto:139:10) at module.exports (/srv/app/node_modules/webpack/lib/util/createHash.js:135:53) at NormalModule._initBuildHash (/srv/app/node_modules/webpack/lib/NormalModule.js:417:16) … reason: 'unsupported', code: 'ERR_OSSL_EVP_UNSUPPORTED'}webpack 4 hashes modules with md4, and OpenSSL 3, bundled since Node 17, blocks it by default. webpack/lib/util/createHash.js in the stack is the giveaway. On a supported Node (22 or 24), upgrading webpack itself to 4.47.0 fixes that path. The md4 support in the 4.47.0 release notes is for "Node >=18", so on Node 17 move to a supported release first. --openssl-legacy-provider also gets it through, but Node.js shipped that flag as a temporary workaround.
[1] Check who creates the hash in the stack. webpack/lib/util/createHash.js or NormalModule._initBuildHash means webpack 4. Node alone reproduces the error, so you can confirm md4 is the cause in one line.
$ node -e 'require("crypto").createHash("md4")'Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:101:19) at Object.createHash (node:crypto:139:10)Node 17 brought OpenSSL 3, and the Node.js 17 release notes describe ERR_OSSL_EVP_UNSUPPORTED as code trying to use an algorithm or key size that OpenSSL 3.0 no longer allows by default. If webpack is not in the stack and the error comes while reading a certificate or key, it is an old key format problem and the fixes below do not apply.
[2] See which webpack is installed. A build tool can pull it in even if you never added it.
$ npm ls webpackapp@1.0.0 /srv/app+-- webpack-cli@3.3.12| `-- webpack@4.46.0 deduped`-- webpack@4.46.0 `-- terser-webpack-plugin@1.4.6 `-- webpack@4.46.0 dedupedreact-scripts@4.0.3 (Create React App 4) pins webpack@4.44.2 (npm view react-scripts@4.0.3 dependencies.webpack → 4.44.2). That is the most common case.
[3] Upgrade webpack to 4.47.0. Its release notes list "Add support for md4 in Node >=18", and the code only switches to its own md4 implementation on Node 18 or later. On Node 22, 4.46.0 failed with the error above and 4.47.0 built with no flags (a one-file test bundle). This fixes webpack's own hashing path only; if a loader or plugin calls md4 itself, that error can remain, so confirm with a real build of your project.
$ npm install -D webpack@4.47.0 --loglevel=error$ npx webpack --mode productionchanged 1 package in 3sHash: b459bb04b575d64c5a9cVersion: webpack 4.47.0Time: 139ms…main.js 950 bytes 0 [emitted] main[4] If another package pins webpack 4, replace it with overrides. Applied to react-scripts@4.0.3, every webpack in the lockfile became 4.47.0.
$ npm pkg set overrides.webpack=4.47.0$ npm install --package-lock-only --ignore-scripts --loglevel=error$ npm ls webpack --package-lock-onlyapp@1.0.0 /srv/app`-- react-scripts@4.0.3 +-- @pmmmwh/react-refresh-webpack-plugin@0.4.3 | `-- webpack@4.47.0 deduped… +-- webpack@4.47.0 overridden--package-lock-only updates only the lockfile and leaves node_modules alone. Once the lockfile looks right, install for real and check the installed version:
$ npm install$ npm ls webpackoverrides swaps a package anywhere in the dependency tree, so the package that pinned it gets a version it did not ask for. After installing, run both the dev server and the production build. The lasting fix is moving that build tool to a release that uses webpack 5.
[5] If you cannot upgrade yet, put --openssl-legacy-provider on that build command only.
$ NODE_OPTIONS=--openssl-legacy-provider npx webpack --mode productionHash: b459bb04b575d64c5a9cVersion: webpack 4.46.0Time: 299ms…main.js 950 bytes 0 [emitted] mainThe flag turns on OpenSSL's legacy provider for the whole process. OpenSSL describes the legacy provider as algorithms that "have commonly fallen out of use, have been deemed insecure by the cryptography community" (MD4, MD2, RIPEMD160 and others). So:
- Do not put
NODE_OPTIONS=--openssl-legacy-providerin~/.bashrc, CI-wide variables, or a DockerfileENV. Node servers in the same shell or image would then run with legacy algorithms allowed. - Keep it in the build script only, for example
"build": "NODE_OPTIONS=--openssl-legacy-provider react-scripts build", and remove it when you do [3] or [4]. - Downgrading to Node 16 is not a workaround. The Node.js release schedule lists v16 as EOL.
[6] Verify. npm ls webpack should show 4.47.0 or later (or 5.x), and npm run build should pass without NODE_OPTIONS. Run echo $NODE_OPTIONS to make sure nothing is left in the shell.
If the same Node upgrade breaks imports, see Node Cannot use import statement.
Check it with the Certificate (PEM · X.509) decoder tool ↗ — calculated in your browser.