node: --openssl-legacy-provider is not allowed in NODE_OPTIONS

avatar
Borislav Hadzhiev

Last updated: Mar 7, 2024
3 min

banner

# node: --openssl-legacy-provider is not allowed in NODE_OPTIONS

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.

node openssl legacy provider is not allowed in node options

# Unset the NODE_OPTIONS environment variable

Open your terminal and run the command that corresponds to your shell type.

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')

unset node options

Try to rerun the npm script or command after deleting the NODE_OPTIONSvariable.

# Verify the NODE_OPTIONS environment variable is not set

You can try to print the NODE_OPTIONS variable to make sure there is no output.

shell
# ๐Ÿ‘‡๏ธ Linux and macOS echo $NODE_OPTIONS # ๐Ÿ‘‡๏ธ on Windows with CMD echo %NODE_OPTIONS% # ๐Ÿ‘‡๏ธ on Windows with PowerShell echo $Env:NODE_OPTIONS

node options not set

For example, if my package.json looks as follows.

package.json
{ "scripts": { "start": "react-scripts start --openssl-legacy-provider", } }
Note that --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.

/etc/ssl/openssl.cnf
##[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.

/etc/ssl/openssl.cnf
[provider_sect] default = default_sect legacy = legacy_sect [default_sect] activate = 1 [legacy_sect] activate = 1

# 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 command and restart your dev server.

If you are on Windows, issue the following commands in CMD.

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.

shell
# ๐Ÿ‘‡๏ธ 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.

# Downgrade to Node.js version 16

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.

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

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 npm cache npm cache clean --force npm install

Restart your development server after issuing the npm install command.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

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