node: --openssl-legacy-provider is not allowed in NODE_OPTIONS
The error “node: --openssl-legacy-provider is not allowed in NODE_OPTIONS” occurs when --openssl-legacy-provider is already set to the NODE_OPTIONS environment variable. To solve this error unset the value in NODE_OPTIONS and rerun the npm script.
In this article we are going to discuss:
- How the error “node: --openssl-legacy-provider is not allowed in NODE_OPTIONS” happens
- How to solve the error “node: --openssl-legacy-provider is not allowed in NODE_OPTIONS”
How the error “node: --openssl-legacy-provider is not allowed in NODE_OPTIONS” happens
The error “node: --openssl-legacy-provider is not allowed in NODE_OPTIONS” happens when NODE_OPTIONS environment variable is already set to a value. You can check the value in the environment variable NODE_OPTIONS by running the below command.
# Command for Linux and macOS
echo $NODE_OPTIONS
# Command for Windows with CMD
echo %NODE_OPTIONS%
# Command for Windows with PowerShell
echo $Env:NODE_OPTIONS
The above command prints the value of NODE_OPTIONS environment variable in the terminal. If something is in the output, then you have to unset the NODE_OPTIONS variable(remove the value) to solve this error.
How to solve the error “node: --openssl-legacy-provider is not allowed in NODE_OPTIONS”
To solve the error “node: --openssl-legacy-provider is not allowed in NODE_OPTIONS”, unset the environment variable NODE_OPTIONS using the below commands.
# Comment for macOS, Linux or Windows Git Bash
unset NODE_OPTIONS
# Comment for Windows CMD (Command Prompt)
set NODE_OPTIONS=
After the running above commands, rerun the npm script.
If the error still exists then try to delete your node_modules and package-lock.json (not package.json) files from your project and run the below commands.
npm cache clean --force
npm install
The above commands will clean the npm and cache and install all dependencies. Next, start your dev server.
Downgrading the Node.js version to 16
After doing the above steps and the error persists, you can consider downgrading the Node.js version to 16. The --openssl-legacy-provider option is only required when you are using the Node.js of version V17 or the latest.
The following command can be used to check the version of node.js that is currently installed.
node -v
If you are running Node.js via nvm(Node Version Manager), then you can easily downgrade the node.js version by using the below command.
nvm install v16
After installing node.js V16, Please delete your node_modules and package-lock.json, clear the npm cache, and reinstall in node modules using the below commands.
npm cache clean --force
npm install
The NODE_OPTIONS is an environment variable that allows us to provide command-line arguments. Since it is an environment variable, it can be specified without modifying any scripts that the node executes. An environment variable is a better way of setting defaults globally because they are inherited by all child processes.
The NODE_OPTIONS environment variable is available in version 8.0.0.
Conclusion
To solve the error “node: --openssl-legacy-provider is not allowed in NODE_OPTIONS”, unset the value in the environment variable NODE_OPTIONS and rerun the npm script. If the error still exists consider downgrading the Node.js to V16.
On datainfinities.com, Read articles all around JavaScript, React, Node.js, PHP, Laravel, and Shopify.
Related Blogs
Cannot read property of undefined in JavaScript
How to Fix error:0308010C:digital envelope routines::unsupported
Find greatest common divisor (GCD) in JavaScript
Remove an item from an array in JavaScript
ERESOLVE unable to resolve dependency tree error when installing npm packages
What are Parameters, Arguments and Arguments Object in JavaScript
How to fix npm ERR! Missing script: "start"
Event Loop and Callback Queue in JavaScript
Invalid hook call. Hooks can only be called inside the body of a function component
Explore All Blogs