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

Remapping keyboard keys to avoid Carpal Tunnel

I am terrible at optimizing my keyboard layout for anything. But off lately, my little…

2 weeks ago

Fixing cookies are blocked for a website with shields down on Brave

I recently switched completely to the Brave browser and have set ad blocking to aggressive…

4 months ago

Generating a QR code using Node.js

I was preparing a slide deck for a hackathon and decided to put in a…

5 months ago

How to clear the global npx cache

I have been using npx a lot lately, especially whenever I want to use a…

6 months ago

Copy/Pasting output from the terminal

Manually copy-pasting the output of a terminal command with a mouse/trackpad feels tedious. It is…

6 months ago

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…

7 months ago
Advertisements