Resolving "error:0308010C:digital envelope routines::unsupported" in Node.js 18
Problem Statement
When migrating Node.js applications (especially Nuxt.js projects) to Node.js version 18 or newer, you may encounter the blocking error: Error: error:0308010C:digital envelope routines::unsupported
. This typically occurs after updating Node.js and related dependencies like ESLint, preventing your development server from starting.
The error stems from cryptographic changes in Node.js 18+ due to its adoption of OpenSSL 3.0. Many older dependencies that rely on encryption algorithms removed from OpenSSL 3.0's default provider suddenly fail, causing your server to crash during startup.
Recommended Solutions
Solution 1: Enable Legacy OpenSSL Provider (Most Practical)
The most effective workaround is enabling OpenSSL's legacy provider via environment variables:
- Set environment variable in package.json scripts (cross-platform):
Modify your package.json to include the legacy flag:
"scripts": {
"dev": "NODE_OPTIONS=--openssl-legacy-provider nuxt dev",
"build": "NODE_OPTIONS=--openssl-legacy-provider nuxt build",
"start": "NODE_OPTIONS=--openssl-legacy-provider nuxt start"
}
- Temporary terminal solution (Linux/macOS):
export NODE_OPTIONS=--openssl-legacy-provider
npm run dev
- Windows Command Prompt/PowerShell:
set NODE_OPTIONS=--openssl-legacy-provider
npm run dev
Security Note
The legacy provider reintroduces deprecated cryptographic algorithms that may have security vulnerabilities. Only use this temporarily while upgrading affected dependencies.
Solution 2: Downgrade to Node.js 16 (Compatibility Fallback)
Node.js 16 uses OpenSSL 1.1.1 which doesn't enforce the same cryptographic restrictions:
Install Node Version Manager (nvm):
bashcurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Install and use Node.js 16:
bashnvm install 16 nvm use 16
Verify Node version:
bashnode -v # Should show v16.x.x
Solution 3: Dependency Upgrade (Long-Term Fix)
Investigate which dependency causes the conflict using the error stack trace:
Check for outdated dependencies:
bashnpm outdated
Update problematic packages starting with:
bashnpm update <package-name>
Recreate lockfile:
bashrm -rf package-lock.json node_modules npm install
Why This Error Occurs
Technical Background
Node.js 18+ switched to OpenSSL 3.0, which introduced stricter algorithm policies. Legacy encryption methods like MD4
, RC4
, and certain EC curves are disabled by default. When a dependency tries to use one of these restricted algorithms, this cryptographic error occurs:
Additional Considerations
- CI/CD Pipelines: Set
NODE_OPTIONS=--openssl-legacy-provider
in your GitHub Actions/YAML configuration - Framework-Specific Issues:js
build: { // Nuxt-specific workarounds may be required here }
- Verify OpenSSL Support:bash
node -p "crypto.getCiphers().join(', ')"
Pro Tip
Search your node_modules
folder for calls to crypto.createHash('md4')
to identify offending dependencies. Modern alternatives like SHA256
are preferred.
Final Recommendations
- Use
--openssl-legacy-provider
for immediate unblocking (with security caveats) - Downgrade to Node.js 16 only if dependent packages need extensive rewrites
- Prioritize dependency upgrades to eliminate legacy cryptographic methods
Most projects find Solution 1 sufficient to resume development immediately while planning dependency upgrades. Always remove the legacy provider flag once all dependencies are compatible with OpenSSL 3.0.