The “error:0308010C:digital envelope routines::unsupported” error is a common issue for developers working with Node.js versions 17 and later, as these versions introduce significant changes in OpenSSL. In this comprehensive guide, we’ll walk you through the steps to diagnose and fix this error.
[lwptoc]
Understanding the Error
Before we dive into the solutions, let’s understand what this error signifies:
Error: error:0308010C:digital envelope routines::unsupported
This error is often encountered when Node.js attempts to use OpenSSL 3.0, and compatibility issues arise during the encryption process.
Quick Fixes
1. Update Your Node.js Environment
Angular projects run on Node.js, and the error might be caused by incompatibilities between Node.js and OpenSSL 3.0. To address this, consider updating your Node.js version to a more recent release.
Check your current Node.js version by running:
node -v
If your Node.js version is below 16.13.0, consider upgrading it. You can use a Node Version Manager (NVM) to manage multiple Node.js versions easily. Here’s how to install and use NVM:
Install NVM on macOS and Linux:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Install NVM on Windows: Follow these instructions to install NVM on Windows.
Once NVM is installed, use it to install a compatible Node.js version (e.g., 16.13.0):
nvm install 16.13.0
Set this Node.js version as the active one:
nvm use 16.13.0
2. Check Your Angular CLI Version
Ensure that you are using a compatible version of Angular CLI. An outdated CLI version might not be well-aligned with the latest Node.js and OpenSSL versions.
Check your Angular CLI version:
ng --version
Update your Angular CLI to the latest version:
ng update @angular/cli@latest
3. Verify Node.js and NPM Environment
Sometimes, the error can be due to inconsistencies in your Node.js and NPM environments. Here’s how to ensure they are set correctly:
Verify your Node.js environment variables by running
echo $NODE_OPTIONS
Ensure that it includes the --openssl-legacy-provider
flag.
If not, set the NODE_OPTIONS
environment variable with the flag:
export NODE_OPTIONS=--openssl-legacy-provider
Verify again that NODE_OPTIONS
now includes the flag.
4. Angular Project Configuration
Check your Angular project configuration for any discrepancies that might trigger the error. Focus on the following areas:
angular.json
File: Verify the project’s build options, especially any custom scripts or configurations that might affect the build process.- Dependencies: Ensure that your project’s dependencies, including
@angular/core
, are up to date. Update any packages if necessary.
Additional Troubleshooting
If none of the quick fixes above resolve the error, you might need to take more aggressive measures.
5. Clean Your Project
Sometimes, old or corrupted build artifacts can cause issues. Clean your Angular project by removing the dist
directory and rebuilding:
rm -rf dist
ng build
6. Reinstall Dependencies
Delete your project’s node_modules
directory and package-lock.json
(or yarn.lock
) file, and then reinstall your dependencies:
For Windows:
rd /s /q "node_modules"
del package-lock.json
del -f yarn.lock
npm cache clean --force
npm install
For macOS/Linux:
rm -rf node_modules
rm -f package-lock.json
rm -f yarn.lock
npm cache clean --force
npm install