openssl-node
is a utility package designed to resolve compatibility issues between Node.js and OpenSSL, particularly the common ERR_OSSL_EVP_UNSUPPORTED
error. This tool provides automated environment configuration, Node.js version checking, and project optimization for seamless development.
Starting with Node.js v17, OpenSSL 3.0 is used by default, and some cryptographic algorithms have been deprecated, leading to issues with tools like Webpack and other dependencies. For example:
Error: error:0308010C:digital envelope routines::unsupported
This package helps developers quickly address these problems by:
- Automatically setting the
NODE_OPTIONS=--openssl-legacy-provider
environment variable. - Checking the current Node.js version and providing compatibility recommendations.
- Offering both CLI and API interfaces for ease of use.
Install openssl-node
using npm:
npm install -g openssl-node
npm install openssl-node
- Environment Configuration: Automatically sets the environment variable to enable OpenSSL legacy mode.
- Node.js Version Check: Detects the current Node.js version and provides downgrade recommendations if necessary.
- CLI Tool: Quickly resolves compatibility issues via the command line.
- API Support: Use programmatically within your project.
After installation, you can run the following command:
openssl-node
The CLI will perform the following:
- Check the current Node.js version.
- Automatically set the environment variable
NODE_OPTIONS=--openssl-legacy-provider
. - Provide recommendations for downgrading Node.js if needed.
$ openssl-node
Checking Node.js version...
Current Node.js version: v19.4.0
Warning: Your Node.js version may have OpenSSL 3 compatibility issues. Consider downgrading to Node.js v16.
Configuring environment...
Environment variable NODE_OPTIONS set to "--openssl-legacy-provider".
OpenSSL compatibility setup completed.
You can also use openssl-node
programmatically in your project:
const opensslNode = require('openssl-node');
// Check Node.js version
opensslNode.checkNodeVersion();
// Configure the environment
opensslNode.configureEnv();
-
checkNodeVersion
Checks the current Node.js version for potential OpenSSL 3 compatibility issues and provides actionable recommendations. -
configureEnv
Automatically sets or updates theNODE_OPTIONS
environment variable to enable OpenSSL legacy compatibility mode.
This package includes unit tests. You can run them using the following command:
npm test
The tests check:
- Whether the environment variable is correctly set.
- Whether the Node.js version check produces expected outputs.
Yes, but it is recommended to manually set NODE_OPTIONS
or use a stable Node.js LTS version (e.g., v16) in production environments to minimize unnecessary dependencies.
Ensure you are using the latest versions of Webpack and related dependencies. If issues continue, consider downgrading Node.js or manually updating your build toolchain.
- Node.js >= v16
- Compatible with Linux, macOS, and Windows systems
If you have suggestions for improvement or encounter any issues, feel free to submit an issue or pull request on GitHub.
This project is licensed under the MIT License. See the LICENSE
file for details.