error:0308010C:digital envelope routines::unsupported [Fixed]

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
6 min

banner

# error:0308010C:digital envelope routines::unsupported [Fixed]

The "error:0308010C:digital envelope routines::unsupported" occurs because Node.js v17 and later use OpenSSL v3.0 which has had breaking changes.

To resolve the error, set the NODE_OPTIONS environment variable to --openssl-legacy-provider when running your development server.

error digital envelope routies unsupported

shell
Error: error:0308010C:digital envelope routines::unsupported Error: digital envelope routines::unsupported opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ], library: 'digital envelope routines', reason: 'unsupported', code: 'ERR_OSSL_EVP_UNSUPPORTED'

# Set the NODE_OPTIONS env variable to --openssl-legacy-provider

The first thing you should try is to set the NODE_OPTIONS environment variable to --openssl-legacy-provider.

Open your terminal and run the specific command for your shell type.

shell
# ๐Ÿ‘‡๏ธ for macOS, Linux or Windows Git Bash export NODE_OPTIONS=--openssl-legacy-provider # ---------------------------------------------------- # ๐Ÿ‘‡๏ธ for Windows CMD (Command Prompt) set NODE_OPTIONS=--openssl-legacy-provider # ---------------------------------------------------- # ๐Ÿ‘‡๏ธ for Windows PowerShell $env:NODE_OPTIONS="--openssl-legacy-provider" # ---------------------------------------------------- # ๐Ÿ‘‡๏ธ for Docker (in your Dockerfile) ENV NODE_OPTIONS="--openssl-legacy-provider"

set node options environment variable

Make sure to use the command that corresponds to your shell type.

windows set node options environment variable

The --openssl-legacy-provider option is needed when using the latest version of Node.js, because Node.js 17 and later uses OpenSSL 3.0 which has had some breaking changes.

If setting the NODE_OPTIONS environment variable helped, you don't have to make any of the following changes.

# Try using the --openssl-legacy-provider flag

If the error persists, try using the --openssl-legacy-provider flag when issuing the command in your package.json file.

Here is an example of how you would do that with create-react-app.

package.json
{ "scripts": { "start": "react-scripts start --openssl-legacy-provider", } }

Simply add --openssl-legacy-provider at the end of your command.

If you get an error that "node: --openssl-legacy-provider is not allowed in NODE_OPTIONS", unset the NODE_OPTIONS environment variable and rerun the command.

shell
# ๐Ÿ‘‡๏ธ for macOS, Linux or Windows Git Bash unset NODE_OPTIONS # ----------------------------------------- # ๐Ÿ‘‡๏ธ for Windows CMD (Command Prompt) set NODE_OPTIONS= # ----------------------------------------- # ๐Ÿ‘‡๏ธ for Windows PowerShell [Environment]::SetEnvironmentVariable('NODE_OPTIONS', '', 'User') [Environment]::SetEnvironmentVariable('NODE_OPTIONS', '', 'Machine')

Try to rerun your script after deleting the environment variable.

# Set the NODE_OPTIONS environment variable

If that doesn't help, try to set the NODE_OPTIONS environment variable right before issuing the command.

Make sure to update the command after the environment variable depending on your use case.
package.json
{ "scripts": { "dev": "NODE_OPTIONS=--openssl-legacy-provider && next dev", "build": "NODE_OPTIONS=--openssl-legacy-provider && next build && next export", } }
If you run the command on Windows, you might get an error - "'NODE_OPTIONS' is not recognized as an internal or external command".

Install the cross-env package to resolve the error.

shell
# ๐Ÿ‘‡๏ธ with NPM npm install cross-env # ๐Ÿ‘‡๏ธ with YARN yarn add cross-env

And prefix the environment variable and the command with cross-env.

package.json
{ "scripts": { "dev": "cross-env NODE_OPTIONS=--openssl-legacy-provider && next dev", "build": "cross-env NODE_OPTIONS=--openssl-legacy-provider && next build && next export", } }

We simply prefixed the command in the package.json script with NODE_OPTIONS=--openssl-legacy-provider, e.g. NODE_OPTIONS=--openssl-legacy-provider YOUR_COMMAND_HERE.

For example, for an Angular app, your package.json script would look similar to the following.

package.json
{ "scripts": { "start": "cross-env NODE_OPTIONS=--openssl-legacy-provider && ng serve -o", } }

If you use create-react-app, update your react-scripts version because the package introduced some fixes regarding its Webpack config in version 5.0.0.

# Update your react-scripts version if you use create-react-app

The error also occurs if you have an outdated version of react-scripts in your create-react-app project.

Open your terminal and run the following command to update your version of react-scripts.

shell
# ๐Ÿ‘‡๏ธ If you use npm npm install react-scripts@latest # ๐Ÿ‘‡๏ธ If you use yarn yarn add react-scripts@latest

npm install react scripts latest

# Delete your node_modules and reinstall your dependencies

If the error persists, try to delete your node_modules and package-lock.json (not package.json) files, rerun the npm install and restart your dev server.

shell
# ๐Ÿ‘‡๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐Ÿ‘‡๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐Ÿ‘‡๏ธ clean your npm cache npm cache clean --force npm install npm install react-scripts@latest

Try to restart your development server after updating your react-scripts version.

Make sure you are running at least version 5.0.1 of react-scripts by checking the package's version in your package.json file.

You can install a specific version using the following command.

shell
# ๐Ÿ‘‡๏ธ if you use npm npm install --save --save-exact react-scripts@5.0.1 # ๐Ÿ‘‡๏ธ if you use yarn yarn add --exact react-scripts@5.0.1

The version of Webpack in react-scripts version 5.0.0+ has been updated which should resolve the issue in your create-react-app project.

# Try updating your NPM packages

Another thing that might help is running the npm audit fix command.

Updating the versions of your packages might solve the error because the maintainers might have introduced security patches in more recent versions.

shell
npm audit fix --force

npm audit fix force

The npm audit fix command looks for vulnerabilities in packages and applies remediations to the package tree.

If the error persists, try running the npm update command.

shell
npm update

If you still get an error, try to delete your node_modules and package-lock.json, rerun the npm install command and restart your development server.

shell
# ๐Ÿ‘‡๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐Ÿ‘‡๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐Ÿ‘‡๏ธ clean your npm cache npm cache clean --force npm install

Try to restart your development server after running the npm audit fix --force command.

If none of the suggestions helped, you can downgrade your Node.js version to 16.13.0 to resolve the error.

# Downgrade to Node.js version 16

You can issue the following command to downgrade your Node.js version to 16.13.0 if you use NVM.

shell
nvm install 16 nvm use 16

nvm install 16 13 0

The command will install and switch to version 16, which should resolve the issue.

If you don't have nvm installed on your machine, follow the instructions in this article.

# Install NVM on macOS and Linux

Open your terminal and run one of the following commands:

shell
# ๐Ÿ‘‡๏ธ using curl curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash # ๐Ÿ‘‡๏ธ using wget wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Running either of the commands above will download the nvm script and run it.

The script clones the nvm repository to ~/.nvm and tries to add 2 lines of code to the correct profile (~/.bash_profile, ~/.zshrc, ~/.profile, ~/.bashrc) to load nvm on system boot.

You can see which shell you are using with the following command:

shell
# ๐Ÿ‘‡๏ธ e.g. zsh echo $0

print-which-shell-is-used

You can verify if nvm was installed successfully by running the following command:

shell
command -v nvm

check if nvm is installed

If nvm was installed successfully, it should output "nvm".

Run the following commands to switch to version 16 of Node.js.

shell
nvm install 16 nvm use 16

nvm install 16 13 0

You can issue the node -v command to verify version 16 of Node.js is installed and active.

shell
node -v

You can also install NVM on macOS or Linux by following the instructions in this article.

# Install NVM on Windows

Note that if you already have Node.js installed on your machine, you have to uninstall it before installing nvm.

To install NVM on Windows:

  1. Open the Releases page of the nvm-windows repository.
  2. Scroll down to the nvm-setup.exe file for the latest release and click on it.

download nvm installer

  1. Accept the license agreement and click "Next".

accept nvm license agreement

  1. Leave the default destination location selected and click "Next".

select destination location

  1. Leave the default symlink directory selected and click "Next".

select symlink directory

  1. Click on the "Install" button.

click on install

The next step is to open PowerShell as an administrator.

To run PowerShell as an administrator:

  1. Click on the Search bar and type "PowerShell".
  2. Right-click on the "PowerShell" application and click "Run as administrator".

run powershell as administrator

Run the nvm ls command to make sure nvm is installed successfully.

PowerShell
nvm ls nvm --version

You can use the nvm list available command to print the available Node.js versions.

PowerShell
nvm list available
  1. Install version 16 of Node.js by running the following command.
PowerShell
nvm install 16

nvm install version 16 windows

  1. After you install Node.js version 16 using nvm, your terminal will show a message with a command you need to run to activate the version.

The command from the screenshot above is nvm use 16.19.0 but it might be different in your case, so make sure to run the correct command to switch to Node.js version 16.

PowerShell
nvm use 16.19.0

switch to node version 16 windows

You can use the node -v command to verify that the active Node.js version is 16.X.

shell
node -v

You can also install NVM on Windows by following the instructions in this step-by-step guide.

# Why the error:0308010C:digital envelope routines::unsupported occurs

The error often occurs when installing Node.js version 17+. Rolling back to version 16.X.X solves it.

The --openssl-legacy-provider option is needed when using the latest version of Node.js, because Node.js 17 and later uses OpenSSL 3.0 which has had some breaking changes.

If you get the error when using Docker, switch your Node version to 16.13.0 (or 16.X.X) in your Dockerfile.

If you still get the error after downgrading to Node version 16, try to delete your node_modules and package-lock.json, rerun the npm install command and restart your development server.

shell
# ๐Ÿ‘‡๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐Ÿ‘‡๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐Ÿ‘‡๏ธ clean your npm cache npm cache clean --force npm install

Restart your development server after issuing the npm install command.

# Additional Resources

If you have difficulties installing and using NVM, check out the following articles:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev