Node.js build stops with 'digital envelope routines::unsupported'
Error: error:0308010C:digital envelope routines::unsupportedShort answer
Node.js 17 and newer ship OpenSSL 3, which no longer loads old algorithms such as MD4 by default. An old webpack 4 toolchain asks for MD4 when it hashes files, and the build dies with error:0308010C. Upgrade the toolchain to webpack 5, or as a stop-gap start Node.js with the legacy OpenSSL provider.
Fix it fast
1Find out which cause you have
Print the Node.js version and the webpack version your project really uses. The error needs both an OpenSSL 3 runtime and an old bundler.
node -p "process.version + ' / openssl ' + process.versions.openssl" npm ls webpack2Match what you see, then jump to its fix
What does the error look like?
Error: error:0308010C:digital envelope routines::unsupportedopensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ]library: 'digital envelope routines', reason: 'unsupported', code: 'ERR_OSSL_EVP_UNSUPPORTED'
Cause 1 of 2
An old webpack asks for the MD4 hash
1Check
webpack 4 defaults its hash function to md4, and OpenSSL keeps MD4 in its legacy provider. If npm ls shows webpack 4.x, this is your cause.
npm ls webpack2Fix
Move the project to a current toolchain. For an Angular app, run the official update steps for the next major version; webpack 5 is what current builders use. If you configure webpack yourself, upgrade it to 5.54 or newer, where output.hashFunction can be set to xxhash64.
npm install --save-dev webpack@5
# webpack.config.js
module.exports = {
output: { hashFunction: 'xxhash64' },
};3Verify
Run the build again on the same Node.js version. The error should be gone.
npm run buildConfirmed by webpack.js.org
Cause 2 of 2
You cannot upgrade yet and need the build to run today
1Check
Node.js has a switch that turns on the OpenSSL 3 legacy provider, which brings MD4 back. It can be passed through NODE_OPTIONS so that npm scripts pick it up.
node --openssl-legacy-provider -p "'legacy provider accepted'"2Fix
Set the flag for the build command only, not for your whole machine. Treat it as a bridge to the upgrade, because it keeps an outdated algorithm enabled.
# macOS / Linux
NODE_OPTIONS=--openssl-legacy-provider npm run build
# package.json (cross-platform, needs: npm i -D cross-env)
"build": "cross-env NODE_OPTIONS=--openssl-legacy-provider ng build"3Verify
The build completes without the unsupported error.
NODE_OPTIONS=--openssl-legacy-provider npm run buildConfirmed by nodejs.org
How do I stop it coming back?
- Keep Angular and its builder on a supported major version so the bundler is not years behind Node.js.
- Pin the Node.js version in one place (.nvmrc or the engines field) and use the same one in CI.
- Do not leave --openssl-legacy-provider in a script after the upgrade; remove it once the build passes without it.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ng serve cannot find the dev-server builder package
Could not find the implementation for builder @angular/build:dev-server
The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.
3 causes, each with a fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix