Last updated: Apr 6, 2024
Reading timeยท6 min
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: 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'
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.
# ๐๏ธ 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"
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.
NODE_OPTIONS
environment variable helped, you don't have to make any of the following changes.--openssl-legacy-provider
flagIf 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
.
{ "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.
# ๐๏ธ 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.
NODE_OPTIONS
environment variableIf that doesn't help, try to set the NODE_OPTIONS
environment variable right
before issuing the command.
{ "scripts": { "dev": "NODE_OPTIONS=--openssl-legacy-provider && next dev", "build": "NODE_OPTIONS=--openssl-legacy-provider && next build && next export", } }
Install the cross-env package to resolve the error.
# ๐๏ธ with NPM npm install cross-env # ๐๏ธ with YARN yarn add cross-env
And prefix the environment variable and the command with cross-env
.
{ "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.
{ "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
.
react-scripts
version if you use create-react-appThe 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
.
# ๐๏ธ If you use npm npm install react-scripts@latest # ๐๏ธ If you use yarn yarn add react-scripts@latest
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.
# ๐๏ธ (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.
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.
# ๐๏ธ 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.
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.
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.
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.
# ๐๏ธ (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.
You can issue the following command to downgrade your Node.js version to
16.13.0
if you use NVM.
nvm install 16 nvm use 16
If you don't have nvm
installed on your machine, follow the instructions in
this article.
Open your terminal and run one of the following commands:
# ๐๏ธ 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:
# ๐๏ธ e.g. zsh echo $0
You can verify if nvm
was installed successfully by running the following
command:
command -v nvm
If nvm
was installed successfully, it should output "nvm".
Run the following commands to switch to version 16 of Node.js.
nvm install 16 nvm use 16
You can issue the node -v
command to verify version 16 of Node.js is installed
and active.
node -v
You can also install NVM on macOS or Linux by following the instructions in this article.
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:
nvm-windows
repository.nvm-setup.exe
file for the latest release and click on
it.To run PowerShell as an administrator:
Run the nvm ls
command to make sure nvm
is installed successfully.
nvm ls nvm --version
You can use the nvm list available
command to print the available Node.js
versions.
nvm list available
nvm install 16
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.
nvm use 16.19.0
You can use the node -v
command to verify that the active Node.js version is
16.X.
node -v
You can also install NVM on Windows by following the instructions in this step-by-step guide.
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.
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.
# ๐๏ธ (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.
If you have difficulties installing and using NVM, check out the following articles: