JavaScript

Fixing “node: –openssl-legacy-provider is not allowed in node_options” error

Advertisements

I recently ran into the “node: –openssl-legacy-provider is not allowed in node_options” error while working with Node 17. It occurs when the NODE_OPTIONS environment variable is set with the value –openssl-legacy-provider. I had set that value for another project I tried recently, which conflicted with this project.

Fixing the “node: –openssl-legacy-provider is not allowed in NODE_OPTIONS” error

Since we know what is causing the error, the simple fix would be to remove that value. To do that, all we need to do is run the following command:

unset NODE_OPTIONS
Bash

While the above command works on Mac and Linux machines, it does not work on Windows. Windows users need to run:

set NODE_OPTIONS=
Bash

After running the command, the error should be fixed. After this, we should be able to run our npm scripts.

Note: Unsetting the NODE_OPTIONS can lead to a “Error:0308010C:digital envelope routines::unsupportedFixing” error for other projects. So you might want to fix the underlying issue of upgrading outdated OpenSSL and/or packages that depend on it. We cover how to upgrade in that post if you are interested in doing that.

Still not working?

Sometimes, the issue still persists even after running that command. We should first verify that the NODE_OPTIONS value was reset by running:

echo $NODE_OPTIONS
Bash

on Mac. For Windows, the command would be:

echo %NODE_OPTIONS%
Bash

If that command prints an empty string, the unsettling worked, and there is either a cached value or some package causing some issue. So we will remove our node_modules folder and re-install the dependencies of the project.

rm -rf node_modules/
npm cache clean --force
npm install
Bash

We might need to remove the package-lock.json (or yarn.lock) as well if the error persists though that is pretty rare.

Switch to a different version of Node

The --openssl-legacy-provider became a thing in Node 17 because of the usage of OpenSSL 3.0. And while downgrading is not the best solution to fix the “node: –openssl-legacy-provider is not allowed in node_options” error.

Some people were able to fix it by upgrading to Node 18 and then unsetting the NODE_OPTIONS value. If we are using nvm:

nvm install 18
nvm use 18
unset NODE_OPTIONS
Bash

Sometimes we just want to move on and not spend too much time into why things are broken. Downgrading to Node 16 might be a last resort but it is one we can lean towards if time is of the essence.

nvm install 16
nvm use 16
Bash

And those are all the ways to solve the “node: –openssl-legacy-provider is not allowed in node_options” error. Hope this post helped you resolve it.

Saransh Kataria

Born in Delhi, India, Saransh Kataria is the brain behind Wisdom Geek. Currently, Saransh is a software developer at a reputed firm in Austin, and he likes playing with new technologies to explore different possibilities. He holds an engineering degree in Computer Science. He also shares his passion for sharing knowledge as the community lead at Facebook Developer Circle Delhi, NCR which is a developer community in Delhi, India.

Share
Published by
Saransh Kataria
Tags: nodenodejs

Recent Posts

How To Get The Hash of A File In Node.js

While working on a project, I wanted to do an integrity check of a file…

2 weeks ago

Native popover API in HTML

Popovers have been a problem that was typically solved by using a third-party solution. But…

3 weeks ago

Node.js 20.6 adds built-in support for .env files

Node.js 20.6 added built-in support for the .env file. This is an excellent addition to the platform…

4 weeks ago

Object destructuring in TypeScript

Object destructuring is a powerful ES 6 feature that can help developers write cleaner code.…

1 month ago

Improve git clone performance in a CI pipeline

Have you felt particularly annoyed by the time it takes to clone a large repository,…

2 months ago

Fix: Hydration failed because the initial UI does not match what was rendered on the server

Within a React or Next.js app, if you encounter the error "Hydration failed because the…

2 months ago
Advertisements