Error:03000086:digital envelope routines::initialization error’, how to fix this error?
The Correct Answer and Explanation is :
The error message “Error:03000086:digital envelope routines::initialization error” is often seen in the context of Node.js applications, particularly when dealing with cryptographic operations such as using OpenSSL. This error can occur due to issues with the OpenSSL version compatibility or the configuration of Node.js.
Steps to fix this error:
- Upgrade or Downgrade Node.js Version:
The error is commonly caused by a mismatch between Node.js and OpenSSL versions. Starting from Node.js v17, Node.js uses OpenSSL 3.0, which is more strict and has breaking changes compared to previous versions. You can resolve this error by either upgrading or downgrading your Node.js version:
- To downgrade to a more stable version (v16 or earlier), use:
bash nvm install 16 nvm use 16 - Alternatively, upgrade Node.js to the latest version:
bash nvm install 18 nvm use 18
- Set the
NODE_OPTIONSEnvironment Variable:
If you are running a Node.js application with a newer version (v17+), you may need to set theNODE_OPTIONSenvironment variable to allow legacy OpenSSL operations. This can help bypass the error:
export NODE_OPTIONS=--openssl-legacy-provider
Or, for Windows, use:
set NODE_OPTIONS=--openssl-legacy-provider
- Rebuild Dependencies:
Sometimes, the issue can be related to native dependencies that are incompatible with the current Node.js version. You can rebuild your dependencies to make sure they are compiled against the correct Node.js version:
npm rebuild
- Check OpenSSL Configuration:
If you’re using a custom installation of OpenSSL, ensure that it’s correctly configured and compatible with your Node.js version. Misconfigurations in OpenSSL can cause cryptographic initialization errors.
Explanation:
This error occurs because Node.js relies on OpenSSL for cryptographic functions such as encryption, decryption, and secure communication. Starting from Node.js v17, the default OpenSSL version is 3.0, which introduces changes to the cryptographic algorithms, resulting in the error message you see. Node.js v16 and earlier use OpenSSL 1.1.1, which is more lenient in handling legacy cryptographic algorithms.
By setting the NODE_OPTIONS environment variable, you’re instructing Node.js to allow older, less secure cryptographic methods, which can resolve compatibility issues with older code or libraries.