If you are getting the react error error:0308010C:digital envelope routines::unsupported then its due to the use of old version of the OpenSSL v3.0 and Node.js v17.
You can easily solve the error if you set the environment variable for NODE_OPTIONS to openssl-legacy-provider while running the development server.
Error: error:0308010C:digital envelope routines::unsupported
Error: digital envelope routines::unsupported
opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'
Solution for the error:0308010C:digital envelope routines::unsupported Error
Lets know all the solutions for the error.
Solution 1: Set the Set the NODE_OPTIONS env variable
The first solution is to set the NODE_OPTIONS environment variable to –openssl-legacy-provider.
Run the below command to achieve that.
For Windows Command Prompt
set NODE_OPTIONS=--openssl-legacy-provider
MacOS or Linux or Windows Git Bash
export NODE_OPTIONS=--openssl-legacy-provider
If you are using the docker then use the below command.
ENV NODE_OPTIONS="--openssl-legacy-provider"
Setting the environment variable for the NODE_OPTIONS is only needed when you are using the latest version of the Node.js. If you are using the Node.js 17 version then this error comes.
Solution 2: Modify the package.json file
If the solution 1 doesn’t work then you can use this solution. Open you package.json file and add the –openssl-legacy-provider flage to the scripts part.
{
"scripts": {
"start": "react-scripts start --openssl-legacy-provider",
}
}
If you are getting the error node: –openssl-legacy-provider is not allowed in NODE_OPTIONS then first unset the environment variable and again run the command.
For Windows CMD
set NODE_OPTIONS=
For macOS, Linux and Windows
unset NODE_OPTIONS
If you are using the windows powershell then use the below commands.
[Environment]::SetEnvironmentVariable('NODE_OPTIONS', '', 'User')
[Environment]::SetEnvironmentVariable('NODE_OPTIONS', '', 'Machine')
Solution 3: Add the NODE_OPTIONS variable to the package.json
If you are still unable to solve the problem then add the NODE_OPTIONS=–openssl-legacy-provider to the “dev” part inside the scripts attribute.
{
"scripts": {
"dev": "NODE_OPTIONS=--openssl-legacy-provider && next dev",
"build": "NODE_OPTIONS=--openssl-legacy-provider && next build && next export",
}
}
You may get the error “‘NODE_OPTIONS’ is not recognized as an internal or external command” when you run the above command. Then in that case install the cross-env package.
Using npm
npm install cross-env
Using Yarn
yarn add cross-env
Also add the “cross-env” before the environment variable like below.
{
"scripts": {
"dev": "cross-env NODE_OPTIONS=--openssl-legacy-provider && next dev",
"build": "cross-env NODE_OPTIONS=--openssl-legacy-provider && next build && next export",
}
}
Solution 4: Update the react-scripts version
If the error still comes then it might be the case of an outdated version of react-scripts. It is used to create a react app using the command create-react-app.
Update the react-scripts using the below command.
npm
npm install react-scripts@latest
YARN
yarn add react-scripts@latest
Solution 5: Update the NPM packages
You can also update all the npm packages to fix the issue.
Use the below command to update it.
npm audit fix --force
When you run the above command the npm looks for vulnerabilities in all the installed packages and fix if there is a problem.
You can also use the npm update command to update all installed packages.
npm update
Solution 6: Downgrade the Node.js version
The error:0308010C:digital envelope routines::unsupported Error comes when you are using the Node.js 17 or latter version. To solve this issue you have to downgrade the Node.js version to 16
To do so run the below command.
nvm install 16
nvm use 16
Conclusion
The error error:0308010C:digital envelope routines::unsupported occurs mostly comes when you are using the latest version of the Node.js that is version latter than 17. So you can downgrade the node.js to version less than 16 or try the other above solutions.
Leave a Reply