Horje
How to Fix "error:0308010C:digital envelope routines::unsupported" in Node.js?

The error message “error:0308010C:digital envelope routines::unsupported” while working with the Node.js we are not alone. This error typically occurs when there are issues with the OpenSSL and cryptographic algorithms being used by the Node.js. It is often related to the compatibility between the Node.js version and the OpenSSL version installed on the system. Here’s a detailed guide to help you troubleshoot and resolve this issue.

Understanding the Error

The error message “error:0308010C: digital envelope the routines::unsupported” indicates that there is an unsupported operation or configuration in the cryptographic library routines. This is usually tied to OpenSSL which Node.js relies on for the implementing secure the network communication and cryptographic operations.

error-(2)

Common Causes

  • Incompatible Node.js Version: Using a version of the Node.js that does not support the default OpenSSL configuration on the system.
  • Deprecated Algorithms: The use of the cryptographic algorithms that are no longer supported by the version of the OpenSSL bundled with the Node.js.
  • Environment Variables: The Certain environment variables might be configured incorrectly leading to the incompatibility issues.
dtrrr-(1)

Here are several approaches we can take to the resolve this issue:

Upgrade/Downgrade Node.js

Depending on the current Node.js version we might need to the upgrade or downgrade to the version that has better compatibility with the system’s OpenSSL.

Upgrade Node.js: Ensure you have the latest stable version of the Node.js which can be installed from the Node.js official website.

# Using Node Version Manager (nvm) to install the latest version

nvm install node

Downgrade Node.js: If you recently upgraded Node.js and started experiencing this issue try downgrading to the earlier version.

# Example: Downgrade to version 16

nvm install 16
nvm use 16

Set Node.js to Use OpenSSL Legacy Provider

Starting from the Node.js v17, some algorithms and functions are disabled by the default due to the OpenSSL 3.0 changes. We can enable the legacy provider to the allow these functions.

Environment Variable: The Set the NODE_OPTIONS environment variable to the use the OpenSSL legacy provider.

export NODE_OPTIONS=--openssl-legacy-provider

Alternatively, we can add this line to the shell profile file (~/.bashrc, ~/.zshrc, etc.) to the make it persistent across the sessions.

"scripts": {
"start": "node --openssl-legacy-provider your-script.js"
}

Update Your Code

If the error is caused by the deprecated or unsupported cryptographic algorithms we might need to the update your code to the use supported algorithms.

Ensure that you are not using the deprecated functions in the crypto module.

const crypto = require('crypto');

// Example of updating a deprecated function
const hash = crypto.createHash('sha256');
hash.update('some data to hash');
console.log(hash.digest('hex'));

Reinstall Node Modules

Sometimes, the issue can be resolved by the reinstalling the node modules especially if they were built using the different version of the Node.js or OpenSSL.

Remove and Reinstall Node Modules:

rm -rf node_modules
npm install

Check for Native Module Compatibility

If your project uses native modules ensure they are compatible with the Node.js version.

Rebuild Native Modules:

npm rebuild

Conclusion

The “error:0308010C:digital envelope routines::unsupported” in the Node.js is typically related to the OpenSSL compatibility issues. By upgrading or downgrading the Node.js enabling the OpenSSL legacy provider the updating your code to the use supported cryptographic algorithms reinstalling the node modules and ensuring the native modules compatibility we can resolve this error. Always ensure your environment and dependencies are up to the date and compatible with the each other to the avoid such issues.




Reffered: https://www.geeksforgeeks.org


Node.js

Related
How to Fix "ReferenceError: __dirname is Not Defined in ES Module Scope" in Javascript How to Fix "ReferenceError: __dirname is Not Defined in ES Module Scope" in Javascript
Add Nested JSON Object in Postman Add Nested JSON Object in Postman
How to Use MongoDB Transactions in Node.js? How to Use MongoDB Transactions in Node.js?
What is a collection in MongoDB? What is a collection in MongoDB?
Multiple MongoDB database Connections in NodeJS Multiple MongoDB database Connections in NodeJS

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
23