openssl-node

1.0.1 • Public • Published

openssl-node

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.


Background

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.

Installation

Install openssl-node using npm:

Global Installation

npm install -g openssl-node

Local Installation

npm install openssl-node

Features

  • 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.

Usage

CLI Usage

After installation, you can run the following command:

openssl-node

The CLI will perform the following:

  1. Check the current Node.js version.
  2. Automatically set the environment variable NODE_OPTIONS=--openssl-legacy-provider.
  3. Provide recommendations for downgrading Node.js if needed.

Example Output:

$ 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.

API Usage

You can also use openssl-node programmatically in your project:

Example Code:

const opensslNode = require('openssl-node');

// Check Node.js version
opensslNode.checkNodeVersion();

// Configure the environment
opensslNode.configureEnv();

File Descriptions

  • checkNodeVersion
    Checks the current Node.js version for potential OpenSSL 3 compatibility issues and provides actionable recommendations.

  • configureEnv
    Automatically sets or updates the NODE_OPTIONS environment variable to enable OpenSSL legacy compatibility mode.


Testing

This package includes unit tests. You can run them using the following command:

npm test

The tests check:

  1. Whether the environment variable is correctly set.
  2. Whether the Node.js version check produces expected outputs.

FAQ

Q: Can I use this tool in production?

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.

Q: What if the problem persists?

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.


Supported Versions

  • Node.js >= v16
  • Compatible with Linux, macOS, and Windows systems

Contributing

If you have suggestions for improvement or encounter any issues, feel free to submit an issue or pull request on GitHub.


License

This project is licensed under the MIT License. See the LICENSE file for details.


Package Sidebar

Install

npm i openssl-node

Weekly Downloads

6

Version

1.0.1

License

MIT

Unpacked Size

10.6 kB

Total Files

10

Last publish

Collaborators

  • y6po