This content originally appeared on DEV Community and was authored by Zach Hugo
envelope routines::unsupported" in Node.js
How to Fix "Error: error:0308010C:digital envelope routines::unsupported" in Node.js
When developing and running Node.js applications, especially those involving encryption and decryption operations, you might encounter the following error:
Error: error:0308010C:digital envelope routines::unsupported
This error is typically caused by a mismatch between the Node.js version and the OpenSSL version you are using. It is especially common when using Node.js v17 and later versions with incompatible OpenSSL versions. In this blog post, we will explore the root cause of this error and provide multiple solutions to fix it. You can choose the solution that best fits your environment and needs.
Understanding the Error
The error message indicates that certain encryption operations cannot be executed due to incompatibility between the Node.js and OpenSSL versions. Starting from Node.js v17, support for OpenSSL 3.0 was introduced, which also means some older encryption algorithms and configurations might no longer be supported.
Solutions
Solution 1: Downgrade Node.js
Downgrade Node.js to a version that is compatible with your current OpenSSL version. For example, Node.js v14 or v16 usually works without this issue.
# If you use nvm (Node Version Manager)
nvm install 16
nvm use 16
Solution 2: Set the OpenSSL Legacy Provider
You can set the NODE_OPTIONS
environment variable to enable the legacy provider for OpenSSL.
For Unix/Linux/MacOS:
export NODE_OPTIONS= - openssl-legacy-provider
For Windows (Command Prompt):
set NODE_OPTIONS= - openssl-legacy-provider
For Windows (PowerShell):
$env:NODE_OPTIONS=" - openssl-legacy-provider"
Solution 3: Add Node.js Flag in package.json
You can also add the flag directly in your project's package.json
file.
"scripts": {
"start": "node - openssl-legacy-provider your-script.js"
}
Replace your-script.js
with the entry point of your application.
Solution 4: Upgrade OpenSSL
If possible, upgrade OpenSSL to a version that is compatible with your Node.js version.
# Example command to upgrade OpenSSL on Ubuntu
sudo apt-get update
sudo apt-get upgrade openssl
Solution 5: Manage Node.js Versions on macOS Using Homebrew
On macOS, you can use Homebrew to manage and switch Node.js versions.
First, ensure you have Homebrew installed. If not, you can install it using the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then, use the following commands to manage Node.js versions:
# Install different Node.js versions
brew install node@20
brew install node@22
# Unlink the current version
brew unlink node@22
# Link to a more stable version
brew link node@20
By following these steps, you can downgrade Node.js to version 20, thus resolving the error.
Summary
The "Error: error:0308010C:digital envelope routines::unsupported" error is primarily caused by incompatibility between Node.js and OpenSSL versions. Depending on your development environment, you can choose one of the following solutions:
- Downgrade Node.js
- Set the OpenSSL Legacy Provider
- Add Node.js Flag in
package.json
- Upgrade OpenSSL
- Manage Node.js Versions on macOS Using Homebrew For macOS users, you can downgrade Node.js versions with the following commands:
brew unlink node@22
brew link node@20
By following these steps, you should be able to resolve the error and run your Node.js application smoothly. I hope this blog post helps you quickly fix the issue and ensures a seamless development experience! If you need further assistance, feel free to leave a comment.
This content originally appeared on DEV Community and was authored by Zach Hugo
Zach Hugo | Sciencx (2024-07-31T03:32:24+00:00) How to Fix “Error: error:0308010C. Retrieved from https://www.scien.cx/2024/07/31/how-to-fix-error-error0308010c/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.