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.
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
BashWhile the above command works on Mac and Linux machines, it does not work on Windows. Windows users need to run:
set NODE_OPTIONS=
BashAfter 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.
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
Bashon Mac. For Windows, the command would be:
echo %NODE_OPTIONS%
BashIf 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
BashWe might need to remove the package-lock.json (or yarn.lock) as well if the error persists though that is pretty rare.
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
BashSometimes 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
BashAnd 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.
I am terrible at optimizing my keyboard layout for anything. But off lately, my little…
I recently switched completely to the Brave browser and have set ad blocking to aggressive…
I was preparing a slide deck for a hackathon and decided to put in a…
I have been using npx a lot lately, especially whenever I want to use a…
Manually copy-pasting the output of a terminal command with a mouse/trackpad feels tedious. It is…
While working on a project, I wanted to do an integrity check of a file…