When working with Node.js and Command line interfaces like create-react-app
and Webpack
, you might get the error:0308010C:digital envelope routines::unsupported
error.
You can fix the error:0308010C:digital envelope routines::unsupported in Node JS by setting the environment variable NODE_OPTIONS=--openssl-legacy-provider
.
This tutorial teaches you the root cause and the different methods to solve this error.
Cause of the Error:0308010C:digital envelope routines::unsupported in Node JS
- You might be using Node.js version 17+. In Node.js version 17+, MD4 algorithms are migrated into OpenSSL 3.0’s legacy provider. Hence, this error will occur if you do not pass the
--openssl-legacy-provider
flag. The legacy provider is not loaded by default and can be added to the application as required. - If you’re working with react application, you might be using the react-script version less than 5.0.0
Option-1 – Solve by Setting the NODE_OPTIONS Environment Variable
To use the openssl-legacy-provider
in your application, you can set the NODE_OPTIONS
environment variable to use this provider.
Use this method when you want to continue working with the Node.js version17+.
You can set the environment variables in the different environments using the following code.
In MacOS, Linux or Windows Git Bash
export NODE_OPTIONS=--openssl-legacy-provider
In Windows CMD (Command Prompt)
set NODE_OPTIONS=--openssl-legacy-provider
In Windows PowerShell
$env:NODE_OPTIONS="--openssl-legacy-provider"
In Docker File(For docker applications)
ENV NODE_OPTIONS="--openssl-legacy-provider"
Option-2 – Solve by Passing the OpenSSL Legacy Provider Flag to Webpack or CLI Tool
Instead of setting the parameter in the node.js options, you can pass the --openssl-legacy-provider
flag to the webpack.
For example, when you have a react app,
- Pass the
--openssl-legacy-provider
flag while starting the react-scripts
Code
{
"scripts": {
"start": "react-scripts start --openssl-legacy-provider",
}
}
Option-3 – Solve By Upgrading react-scripts to v5.0.0 or Higher
If you have created the react applications using the Create React App command, you need to upgrade the react-scripts to V5.0.0 or higher to solve the error:0308010C:digital envelope routines::unsupported
error.
To check the current version of the react-scripts
,
- Look in the
devDependencies
section of the project’spackage.json
file
{
"name": "create-react-app-example",
"version": "0.1.0",
"devDependencies": {
"react-scripts": "3.2.0"
}
}
The react-scripts
might also be in the dependencies section.
To upgrade the react-scripts version to V5.0.0 or higher, use the below command:
Using NPM
npm install --save --save-exact [email protected]
Using YARN
yarn add --exact [email protected]
After upgrading the react-scripts
version, you might need to reinstall the dependencies. Before reinstalling the dependencies,
Delete the node_modules folder using the following command:
rm –rf node_modules
Delete the package-lock.json file using the following command:
rm –rf package.lock.json
Clean the npm
cache using the following command:
npm cache clean --force
Reinstall the dependencies using the following command:
npm install
Now your package.json file will look like the following:
{
"name": "create-react-app-example",
"version": "0.1.0",
"devDependencies": {
"react-scripts": “5.0.0”
}
}
Option-4 – Downgrading the Node.js version to 16 or Less
If the above solutions are inappropriate for your environment, you can downgrade the Node.js version to 16 or less.
To check the current Node.js version, use the following command:
node -v
Output
v18.14.2
You can download the Node JS version 16.20.0 from the Node JS website and install it.
Downgrade Using NVM
If you’re using Node.js via nvm
, you can downgrade the node.js version using the following command:
nvm install v16
This is how you can solve the Digital Envelop Routines Unsupported error.
If you have any questions, feel free to comment below.