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:
While the above command works on Mac and Linux machines, it does not work on Windows. Windows users need to run:
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:
on Mac. For Windows, the command would be:
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.
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
--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:
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.
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.