Last updated: Mar 7, 2024
Reading timeยท3 min
The error "node: --openssl-legacy-provider is not allowed in NODE_OPTIONS"
occurs when the NODE_OPTIONS
environment variable is set to
--openssl-legacy-provider
.
To solve the error, unset the environment variable and rerun your npm
script.
Open your terminal and run the command that corresponds to your shell type.
# ๐๏ธ 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')
npm
script or command after deleting the NODE_OPTIONS
variable.NODE_OPTIONS
environment variable is not setYou can try to print the NODE_OPTIONS
variable to make sure there is no
output.
# ๐๏ธ Linux and macOS echo $NODE_OPTIONS # ๐๏ธ on Windows with CMD echo %NODE_OPTIONS% # ๐๏ธ on Windows with PowerShell echo $Env:NODE_OPTIONS
For example, if my package.json
looks as follows.
{ "scripts": { "start": "react-scripts start --openssl-legacy-provider", } }
--openssl-legacy-provider
comes last. The order of the parameters is important.I can start my create-react-app
application with the npm run start
command
without any issues.
If you are on Fedora/CentOS and the error persists, try to uncomment the
following lines in your /etc/ssl/openssl.cnf
file.
##[provider_sect] ##default = default_sect ##legacy = legacy_sect ## ##[default_sect] ##activate = 1 ## ##[legacy_sect] ##activate = 1
After you uncomment the lines, your /etc/ssl/openssl.cnf
file will look as
follows.
[provider_sect] default = default_sect legacy = legacy_sect [default_sect] activate = 1 [legacy_sect] activate = 1
If the error persists, try to delete your node_modules
and
package-lock.json (not
package.json
) files, rerun the npm install
command and restart your dev
server.
If you are on Windows, issue the following commands in CMD.
# ๐๏ธ Windows rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐๏ธ clean npm cache npm cache clean --force npm install
If you are on macOS or Linux, issue the following commands in bash
or zsh
.
# ๐๏ธ macOS or Linux rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐๏ธ clean npm cache npm cache clean --force npm install
Try to restart your IDE and development server after reinstalling your modules.
If none of the suggestions helped, you can try to downgrade your Node.js version
to 16
.
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.
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, install it by following the instructions in the relevant article:
The error often occurs when installing Node.js version 17+. Rolling back to version 16.X.X. solves it.
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 npm cache npm cache clean --force npm install
Restart your development server after issuing the npm install
command.
You can learn more about the related topics by checking out the following tutorials: