If you are facing this error and you do not want to change your main configuration, an easy fix would be to use the following approach. I am not sure if it is recommended as a good practice, though.
Feel free to correct it.
Initially, let’s say this is the scripts section of my package.json
file:
...
"version": "1.0.0",
"scripts": {
...
"build": "npm run build:test-app:testing",
"build:test-app:testing": "ng build test-app --deploy-url https://test-app.com/ --configuration=test-config",
...
},
"private": true,
...
In order to use this export NODE_OPTIONS=--openssl-legacy-provider
you can do the following:
"version": "1.0.0",
"scripts": {
....
"build": "NODE_OPTIONS=--openssl-legacy-provider npm run build:test-app:testing”,
"build:test-app:testing": "NODE_OPTIONS=--openssl-legacy-provider ng build test-app --deploy-url https://test-app.com/ --configuration=test-config"
...
},
"private": true,
Take note of the build scripts. I have added an option: NODE_OPTIONS=--openssl-legacy-provider
This helps solve this error in Node.js version 17.
For those with the flexibility of changing the build system’s Node.js version, just switch to a version lower that 17, e.g., version 16.
For Docker, the use case of using this initially, which always pulls the latest version:
...
FROM node:alpine
...
You can switch to something like:
...
FROM node:16-alpine3.12
...
The error:0308010C:digital envelope routines::unsupported
error happens in Node.js when a JavaScript module still uses a flawed OpenSSL version that is incompatible with the version Node.js uses.
error:0308010C:digital envelope routines::unsupported
error occurring.
To fix it, downgrade to Node.js v16.13.0, or use the npm audit fix --force
command to upgrade your packages to versions that use the updated OpenSSL version.
JavaScript: The Definitive Guide
Take your understanding of JavaScript to the next level with this international best seller. Build your mastery with detailed explanations and illuminating code examples.
Why does the error:0308010C:digital envelope routines::unsupported
error occur in Node.js?
In Node.js v17, the Node.js team patched an OpenSSL security vulnerability. This fix introduced a breaking change; if you try to use OpenSSL in Node.js v17 or later versions without also updating those modules that use previous OpenSSL versions, you’ll get this error.
And you’ll get it the next time Node.js is updated to use a newer OpenSSL version with breaking changes and you haven’t updated the OpenSSL-dependent libraries.
Fix: Upgrade NPM packages
To fix the error:0308010C:digital envelope routines::unsupported
error, update the Node.js packages causing the error to the latest version.
Run npm audit fix
to fix vulnerabilities
You can run the npm audit fix
command to identify those packages using the outdated OpenSSL version and fix them automatically.
npm audit fix
reviews the project’s dependency tree to identify packages that have known vulnerabilities, and attempts to upgrade and/or fix the vulnerable dependencies to a safe version.
npm audit fix --force
If you want to install semver
major updates to vulnerable packages, you can use the --force
option.
Be cautious with this option: it could potentially break your project.
yarn-audit-fix
If you’re a Yarn user, you can use the yarn-audit-fix
package to do what npm audit fix
does.
Upgrade Webpack to v5
If you’re using Webpack directly to bundle your files, you can upgrade it to version v5 – specifically, v5.61.0 – to fix the error:0308010C:digital envelope routines::unsupported
error.
npm i webpack@latest
# Yarn
yarn add webpack@latest
If instead, you’re using a tool like Create React App and the Vue CLI that uses Webpack internally, you’ll upgrade the tool to a version that doesn’t have this error.
Fix for Create React App: Upgrade react-scripts
to v5
If you’re using Create React App then you can fix the error:0308010C:digital envelope routines::unsupported
error by upgrading react-scripts
to version 5, which comes with the newer Webpack version 5.
Install version 5 or later with this command:
npm i react-scripts@latest
# Yarn
yarn add react-scripts@latest
Fix for Vue CLI: Upgrade to v5
Similarly for the Vue CLI, you can fix the error:0308010C:digital envelope routines::unsupported
error by upgrading the Vue CLI to version 5 which also comes with the newer Webpack version 5.
Install Vue CLI version 5 or later with this command:
npm update -g @vue/cli
# OR
yarn global upgrade --latest @vue/cli
More info on how to upgrade the Vue CLI here.
Fix: Use --openssl-legacy-provider
option
To fix the error:0308010C:digital envelope routines::unsupported
error in Node.js, you can also use the --openssl-legacy-provider
option when running the script.
This solution is more of a hack though: it leaves your app open to security threats.
The --openssl-legacy-provider
option is only available in Node version 17 or later.
Run with script
So for the start
script, you’ll use this command:
export NODE_OPTIONS=--openssl-legacy-provider && npm run start
# Windows
set NODE_OPTIONS=--openssl-legacy-provider && npm run start
Modify script
You can also set this directly in the script to avoid needless repetition.
On Linux/Mac:
{
...
"scripts": {
"start": "export NODE_OPTIONS=--openssl-legacy-provider && webpack serve",
"build": "webpack --mode production"
}
...
}
On Windows:
{
...
"scripts": {
"start": "set NODE_OPTIONS=--openssl-legacy-provider && node .",
"build": "set NODE_OPTIONS=--openssl-legacy-provider && node build.js"
}
...
}
Make sure the script is cross-platform
But now the scripts aren’t cross-platform.
They’ll obviously be problematic when collaborating and team members use other operating systems. What do we do? We install the cross-env
NPM module and run the script with it.
npm i cross-env
# Yarn
yarn add cross-env
{
...
"scripts": {
"start": "cross-env NODE_OPTIONS=--openssl-legacy-provider webpack .",
"build": "cross-env NODE_OPTIONS=--openssl-legacy-provider node build.js"
},
"devDependencies": {
"cross-env": "^7.0.3"
}
...
}
Now the script runs successfully on every platform.
Fix for Vue CLI
So to fix the error:0308010C:digital envelope routines::unsupported
error when using Vue with the Vue CLI, install the cross-env
module and set the --openssl-legacy-provider
option:
{
...
"scripts": {
"serve": "cross-env NODE_OPTIONS=--openssl-legacy-provider vue-cli-service serve",
...
},
"devDependencies": {
"cross-env": "^7.0.3"
...
}
...
}
Fix for Create React App
And to fix the error:0308010C:digital envelope routines::unsupported
error when using React with Create React App, install the cross-env
module and set the --openssl-legacy-provider
option.
{
...
"scripts": {
"serve": "cross-env NODE_OPTIONS=--openssl-legacy-provider ",
...
},
"devDependencies": {
"cross-env": "^7.0.3"
...
}
...
}
Fix: Downgrade to Node.js v16.13.0
To fix the error:0308010C:digital envelope routines::unsupported
error in Node.js, downgrade your Node.js version to 16.13.0
.
This solution is more of a hack though, as it leaves your app open to security threats.
Install from the official website
Use this official link to download Node.js v16.13.0.
Install with Chocolatey
If you’re using Chocolatey, Node.js is available as the nodejs
package, meaning you can easily install it in a terminal using the following command.
# Use current LTS version
choco install nodejs --version=18.5.0
Install with nvm
If you’re using nvm
or nvm-windows
, use these commands to quickly install and switch to Node.js v16.13.0.
nvm install 16.13.0
nvm use 16.13.0
Key takeaways
- The
error:0308010C:digital envelope routines::unsupported
error in Node.js occurs when a JavaScript module uses an outdated OpenSSL version that is incompatible with the current Node version. This typically happens when Node.js v17 or later versions are used without updating the modules that use previous OpenSSL versions. - To fix this error, you can downgrade to Node.js v16.13.0, or use the
npm audit fix --force
oryarn-audit-fix
command to upgrade your packages to versions that use the updated OpenSSL version. - If you’re using Webpack, you can upgrade it to version v5.61.0 to fix the error. For Create React App and Vue CLI, you can upgrade them to v5.
- Another way to fix the error is to use the
--openssl-legacy-provider
option when running the script. However, this solution leaves your app open to security threats and is only available in Node version 17 or later. - Downgrading to Node.js v16.13.0 is another way to fix the error. However, this solution also leaves your app open to security threats. You can install this version from the official website, or use
Chocolatey
,nvm
, ornvm-windows
to install and switch to this version.
When running JavaScript applications with Node, you might see the following error:
Error: error:0308010C:digital envelope routines::unsupported
After some research, I found this error occurs because there’s a breaking change in Node.js version 17, which used OpenSSL version 3 by default.
This article explains why this error occurs and several ways you can fix it in practice.
Why this error occurs
Command line tools like Webpack uses the “MD4 algorithm” to create file hashes. These file hashes are then used to keep track of changes in your JavaScript files.
By default, OpenSSL version 3 didn’t enable the MD4 algorithm support. If you upgraded Node.js to version 17 and above, you’ll see this error when building an application using Webpack.
For example, this error appears when running a React application:
$ npm start
Starting the development server...
Error: error:0308010C:digital envelope routines::unsupported
Near the end of the terminal, you should see opensslErrorStack
logs similar to this:
{
opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'
}
The error stack is confusing because nothing in it points to the MD4 algorithm which is not enabled by default in OpenSSL 3. I only found out by reading discussions on GitHub.
It doesn’t matter whether you run a React, Vue, Angular, or any other application. You’ll get this error because the Webpack build failed.
1. To fix this error, you need to upgrade to Webpack 5
The fix for this error is released in Webpack 5.61.0, in which the maintainer sokra added an MD4 implementation using Web Assembly.
If you’re using Webpack directly in your package.json
file, then you can upgrade Webpack to version 5:
npm install webpack@latest
Unfortunately, if Webpack is used internally by your developer tool (like Create React App and vue-cli) then you can’t upgrade Webpack version like this.
You need to wait until the tool released a new version that fix this error, or you can use one of the solutions below.
2. Add --openssl-legacy-provider
flag to your build script
As an alternative solution, you can add the --openssl-legacy-provider
flag to the build script defined in package.json
.
The Open SSL legacy provider is a collection of legacy algorithms that are no longer in common use, such as MD2, MD4, MDC2, etc.
You can add the flag to enable these legacy algorithms. Here are some examples for Create React App and vue-cli apps:
// For React:
{
"scripts": {
"start": "react-scripts start --openssl-legacy-provider"
}
}
// For Vue:
{
"scripts": {
"serve": "vue-cli-service serve --openssl-legacy-provider"
},
}
If you see an error saying Error: Unknown argument: openssl-legacy-provider, then you can set the NODE_OPTIONS
environment variable before running the build command.
Depending on your terminal, run one of the commands below:
# macOS, Linux and Windows Git Bash
export NODE_OPTIONS=--openssl-legacy-provider
# Windows Command Prompt:
set NODE_OPTIONS=--openssl-legacy-provider
# Windows PowerShell:
$env:NODE_OPTIONS="--openssl-legacy-provider"
Then run your build command, for example:
export NODE_OPTIONS=--openssl-legacy-provider
npm start
With the legacy provider enabled, the error should disappear.
3. If you use Create React App, upgrade react-scripts to v5
If you use Create React App, then you can fix this error by upgrading react-scripts
to v5.
You can run one of the following commands:
# For npm:
npm install react-scripts@5
# For Yarn:
yarn add react-scripts@5
The react-scripts
package now uses the MD5 algorithm to generate Webpack modules and chunks.
The error should disappear when you run the npm start
command.
4. Downgrade to Node v16
If you have a complex application, then upgrading Webpack to version 5 can be quite difficult.
You can downgrade your Node.js to version 16 as you prepare a migration plan from version 4 to version 5.
If you use nvm, then you can run the following commands to install and use Node v16:
nvm install 16
nvm alias default 16
nvm use 16
# Check node version:
node -v
If you use Volta, run the commands below:
volta install node@16
# Check node version:
node -v
Volta automatically set the default node version to the most recently installed.
Next, you need to delete the node_modules
folder and run npm install
so that all dependencies on your package get rebuilt using Node v16. Some dependencies may cause other errors when build with a different Node version.
Although this fix works, keep in mind that you eventually need to upgrade to Node v18 when Node v16 reached the end of life in September 2023.
You should create a migration plan to upgrade Webpack to version 5 in the meantime.
Summary
The error 0308010c:digital envelope routines::unsupported
occurs because Webpack used the MD4 algorithm in its build process, which is no longer supported by default in the latest Node.js version.
To resolve this error, you need to upgrade Webpack to version 5 which implements its own MD4 algorithm without depending on Node’s implementation. If you can’t upgrade Webpack yet, you need to add the --openssl-legacy-provider
flag when starting the Node server.
The error is somewhat frustrating because it’s not clear what you should do, but at least the fix is easy to implement.
I hope this tutorial helps. Thanks for reading and Happy coding! 🙌
Table of Contents
Hide
- What is error:0308010C:digital envelope routines::unsupported?
- How to resolve error:0308010C:digital envelope routines::unsupported?
- Solution 1: Add the legacy OpenSSL in package.json
- Solution 2: Downgrade Node.JS to Long Term Support(LTS)
- Solution 3: Setting openssl-legacy-provider Globally
- Conclusion
The error:0308010C:digital envelope routines::unsupported is mainly observed while creating the react application using the Node.JS version 17 or above and using the webpack@4 version.
In this tutorial, we will look at what is error:0308010C:digital envelope routines::unsupported and how to resolve this issue in your application.
So today, when we are setting up and running the React project using the latest version of Node.JS 17 or above, we ran into the below issue.
[webpack-cli] 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 (/opt/src/node_modules/webpack/lib/util/createHash.js:155:18)
opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'
The error can also occur if you build the application using docker build since it pulls the latest version of Node.JS by default.
This error is because node.js 17 uses OpenSSL3, which has changed code for initialization context of md family (including md4), and this is a breaking change.
We can find more details about the OpenSSL3 upgrade over here.
The Node JS version 17 is not the LTS (Long Term Support), and it is not compatible with the webpack version 4.
How to resolve error:0308010C:digital envelope routines::unsupported?
There are multiple ways to resolve the issue. Let us take a look at each of these solutions.
Solution 1: Add the legacy OpenSSL in package.json
If you still want to use Node.js 17 or above and resolve the issue, you can go to package.json and modify the line.
"start": "react-scripts start"
to
"start": "react-scripts --openssl-legacy-provider start"
Changing this script in package.json makes Node.js use OpenSSL 3 in the legacy mode, which means you are running with known insecure algorithms.
Solution 2: Downgrade Node.JS to Long Term Support(LTS)
The other alternate way is to downgrade the Node.JS to LTS version 16.14.0, to resolve the issue.
There are various ways to install and use Node.js versions. One of the best ways is to use Node Version Manager to manage multiple node versions.
Step 1: Install the Node Version manager using the below command.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Step 2: You can install the specific node.js version or just use the below command to install the node.js LTS version.
nvm install --lts
Step 3: Set the node.js to use the latest LTS version using the following command.
nvm use --lts
In the case of the Docker build, you can modify the DockerFile something like this.
...
FROM node:alpine
...
to
...
FROM node:16-alpine3.12
...
Solution 3: Setting openssl-legacy-provider Globally
Setting the NODE_OPTIONS
is not a recommended approach, but you can still try this on your local machine as a quick fix.
The same can be tried in the case of the Docker build. All you need to do is add the below line in your DockeFile to resolve the issue.
RUN export NODE_OPTIONS=--openssl-legacy-provider && yarn build && yarn install --production --ignore-scripts --prefer-offline
Conclusion
The error:0308010C:digital envelope routines::unsupported occurs with the Node.js version 17 as it’s not the LTS version, and there is a breaking change in the OpenSSL.
We can resolve the issue by downgrading the Node.js version to LTS (16.14.0) or by modifying the package.json start script to "start": "react-scripts --openssl-legacy-provider start"
Srinivas Ramakrishna is a Solution Architect and has 14+ Years of Experience in the Software Industry. He has published many articles on Medium, Hackernoon, dev.to and solved many problems in StackOverflow. He has core expertise in various technologies such as Microsoft .NET Core, Python, Node.JS, JavaScript, Cloud (Azure), RDBMS (MSSQL), React, Powershell, etc.
Sign Up for Our Newsletters
Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.
By checking this box, you confirm that you have read and are agreeing to our terms of use regarding the storage of the data submitted through this form.
Describe the bug
I installed the latest Node version, currently, it’s 17.2.0
. When I try to start the project in development mode with the command npm run start
, it throws an error & it’s unable to start the project for development.
Pre-requisites:
- Node’s version
17.2.0
. - NPM’s version
8.1.41
. - OS: Window 11
- CLI:
Windows PowerShell
Steps to reproduce:
- run the command
npx create-react-app hello-world
- navigate to the project’s root & run the command:
npm run start
Expected results
It was expected to compile in dev mode & launch React’s app in the browser like in the screenshot below: ( which it’s using Node’s version 16.13.1
)
Actual results
It doesn’t compile & it throws the following error instead:
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:\Users\manue\Desktop\projects\hello-world\node_modules\webpack\lib\util\createHash.js:135:53)
at NormalModule._initBuildHash (C:\Users\manue\Desktop\projects\hello-world\node_modules\webpack\lib\NormalModule.js:417:16)
at handleParseError (C:\Users\manue\Desktop\projects\hello-world\node_modules\webpack\lib\NormalModule.js:471:10)
at C:\Users\manue\Desktop\projects\hello-world\node_modules\webpack\lib\NormalModule.js:503:5
at C:\Users\manue\Desktop\projects\hello-world\node_modules\webpack\lib\NormalModule.js:358:12
at iterateNormalLoaders (C:\Users\manue\Desktop\projects\hello-world\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
at iterateNormalLoaders (C:\Users\manue\Desktop\projects\hello-world\node_modules\loader-runner\lib\LoaderRunner.js:221:10)
C:\Users\manue\Desktop\projects\hello-world\node_modules\react-scripts\scripts\start.js:19
throw err;
^
Error: error:0308010C:digital envelope routines::unsupported
at Object.createHash (node:crypto:130:10)
at module.exports (C:\Users\manue\Desktop\projects\hello-world\node_modules\webpack\lib\util\createHash.js:135:53)
at NormalModule._initBuildHash (C:\Users\manue\Desktop\projects\hello-world\node_modules\webpack\lib\NormalModule.js:417:16)
at C:\Users\manue\Desktop\projects\hello-world\node_modules\webpack\lib\NormalModule.js:452:10
at C:\Users\manue\Desktop\projects\hello-world\node_modules\webpack\lib\NormalModule.js:323:13
at C:\Users\manue\Desktop\projects\hello-world\node_modules\loader-runner\lib\LoaderRunner.js:367:11
at C:\Users\manue\Desktop\projects\hello-world\node_modules\loader-runner\lib\LoaderRunner.js:233:18
at context.callback (C:\Users\manue\Desktop\projects\hello-world\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
at C:\Users\manue\Desktop\projects\hello-world\node_modules\babel-loader\lib\index.js:59:103 {
opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'
}
This is a screenshot of the issue:
Workaround
- uninstall Node’s version
17.2.0
- install Node’s version
16.13.1
- run
npm run start
The app should compile now.