When you try to run an Angular application, then you may come across the error “digital envelope routines unsupported” with the error code ERR_OSSL_EVP_UNSUPPORTED like this
The problem is because of an issue with webpack.
Solution for “digital envelope routines unsupported” or ERR_OSSL_EVP_UNSUPPORTED in Angular applications
Solution 1
Open your command prompt / terminal and run the following command
Windows users
set NODE_OPTIONS=--openssl-legacy-provider
Mac users
export NODE_OPTIONS=--openssl-legacy-provider
After executing the command, now you can use ng serve command in your command prompt/ terminal which solves digital envelope routines unsupported error in Angular applications.
Please note that, after executing the above code, you may not be able to run the commands such as “code .” to open Visual Studio Code and you may get the error “Code.exe –openssl-legacy-provider is not allowed in NODE_OPTIONS”. To solve this problem, you can close and re-open the command prompt to clear the values set by the previous command for that session.
If you want to unset the values, set by the previous command without leaving the command prompt, you can do it by re-setting to empty values like this (there is no unset command, if you use, you will get unset is not recognized as an internal or external command )
set NODE_OPTIONS=
Solution 2
Another way to solve this problem is by editing your package.json file
Windows users can change the value of start in scripts object from “ng serve” to “set NODE_OPTIONS=–openssl-legacy-provider && ng serve”
example:
"start": "set NODE_OPTIONS=--openssl-legacy-provider && ng serve ",
Similarly, Mac users can change the value like this
"start": "export NODE_OPTIONS=--openssl-legacy-provider && ng serve ",
Please note that, with the above changes in the package.json file, now you can use “npm start” to run the application.
Above given solution worked for me