Error message "error:0308010C:digital envelope routines::unsupported"
node.jsReactjsWebpackWebstormnode.js Problem Overview
I created the default IntelliJ IDEA React project and got this:
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:67:19)
at Object.createHash (node:crypto:130:10)
at module.exports (/Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/util/createHash.js:135:53)
at NormalModule._initBuildHash (/Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:417:16)
at handleParseError (/Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:471:10)
at /Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:503:5
at /Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:358:12
at /Users/user/Programming Documents/WebServer/untitled/node_modules/loader-runner/lib/LoaderRunner.js:373:3
at iterateNormalLoaders (/Users/user/Programming Documents/WebServer/untitled/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
at iterateNormalLoaders (/Users/user/Programming Documents/WebServer/untitled/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
/Users/user/Programming Documents/WebServer/untitled/node_modules/react-scripts/scripts/start.js:19
throw err;
^
It seems to be a recent issue - webpack ran into this 4 days ago and is still working on it.
node.js Solutions
Solution 1 - node.js
Here is two option now -
1. Try to uninstall Node.js version 17+ and reinstall the Node.js version 16+
-
You can re install the current LTS node js version from their official site. or more specific downloads from here;
-
You can use NVM (Node Version Manager)
- Linux and Mac users can use this nvm package - https://github.com/nvm-sh/nvm
- Windows users can use this nvm package - https://github.com/coreybutler/nvm-windows
2. Open terminal and paste these as described :
Linux & Mac OS (windows git bash)-
export NODE_OPTIONS=--openssl-legacy-provider
Windows command prompt-
set NODE_OPTIONS=--openssl-legacy-provider
Reference link.
Solution 2 - node.js
In your package.json: change this line
"start": "react-scripts start"
to
"start": "react-scripts --openssl-legacy-provider start"
Solution 3 - node.js
If we use the current LTS version of Node.js then this error will not come. Downgrade your Node.js version to the current LTS version (16.13.0).
There can be multiple ways to install the required version. One of them is using nvm (Node.js version manager).
-
Step 1: Install nvm (if not installed, follow Install Node.js Locally with Node Version Manager (nvm))
-
Step 2:
nvm install 16.13.0
(or lts)
Solution 4 - node.js
It's the Node.js version.
I have this error on Node.js 17, but it's fine when I switch my Node.js version to an older version (16) by using nvm
.
Solution 5 - node.js
Some top answers did not work.
export NODE_OPTIONS=--openssl-legacy-provider
And some top answers were not applicable, modifying package.json
file:
"start": "react-scripts --openssl-legacy-provider start"
This is caused by the latest node.js V17
compatible issues with OpenSSL
, see this and this issue on GitHub.
The easiest thing is just downgrade from node.js V17
to node.js V16
. See this post on how to downgrade node.js
.
Solution 6 - node.js
I found the commands below on GitHub:
For Windows, use the below command in cmd:
set NODE_OPTIONS=--openssl-legacy-provider
For Unix, use:
export NODE_OPTIONS=--openssl-legacy-provider
Solution 7 - node.js
This worked for me (downgrading from Node.js 17 to Node.js 16):
nvm install --lts
nvm use --lts
Using Node.js Version Manager (for Windows).
Solution 8 - node.js
> Failed to construct transformer: Error: error:0308010C:digital envelope routines::unsupported
The simplest and easiest solution to solve the above error is to downgrade Node.js to v14.18.1. And then just delete folder node_modules
and try to rebuild your project and your error must be solved.
Solution 9 - node.js
This solution worked for me.
This error is coming in Node.js version 17+, so try to downgrade the Node.js version.
- Uninstall Node.js from the computer.
- Download Node.js version 16 and install it again from https://nodejs.org/download/release/v16.13.0/
That's all.
Solution 10 - node.js
check
node -v
v17.4.0
then roll back to node --lts (node v16.13.2 (npm v8.1.2)) for that use nvm
for bash shell
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
for zsh shell
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | zsh
after nvm install
nvm install --lts
check
node -v
v16.13.2
retry again
Solution 11 - node.js
I faced this issue in Docker build, and I have added this line in the Docker file:
RUN export NODE_OPTIONS=--openssl-legacy-provider && yarn build && yarn install --production --ignore-scripts --prefer-offline
For local development, add the switch in file package.json.
Solution 12 - node.js
If you are facing this error and you do not want to change your main configuration, an easy fix would be to use the following approach. I am not sure if it is recommended as a good practice, though.
Feel free to correct it.
Initially, let’s say this is the scripts section of my package.json
file:
...
"version": "1.0.0",
"scripts": {
...
"build": "npm run build:test-app:testing",
"build:test-app:testing": "ng build test-app --deploy-url https://test-app.com/ --configuration=test-config",
...
},
"private": true,
...
In order to use this export NODE_OPTIONS=--openssl-legacy-provider
you can do the following:
"version": "1.0.0",
"scripts": {
....
"build": "NODE_OPTIONS=--openssl-legacy-provider npm run build:test-app:testing”,
"build:test-app:testing": "NODE_OPTIONS=--openssl-legacy-provider ng build test-app --deploy-url https://test-app.com/ --configuration=test-config"
...
},
"private": true,
Take note of the build scripts. I have added an option: NODE_OPTIONS=--openssl-legacy-provider
This helps solve this error in Node.js version 17.
For those with the flexibility of changing the build system's Node.js version, just switch to a version lower that 17, e.g., version 16.
For Docker, the use case of using this initially, which always pulls the latest version:
...
FROM node:alpine
...
You can switch to something like:
...
FROM node:16-alpine3.12
...
Solution 13 - node.js
This worked for me in my app expo (downgrading from Node.js 17 to Node.js 12 or 14).
If you have nvm installed you can change the version of node:
First check versions of Node.js in nvm:
nvm list
Second, install version 12 or 14:
nvm install v12.22.8
Solution 14 - node.js
If you're using react-scripts
you can now simply upgrade to version 5.0.0 (or above) which seems to have addressed this issue (it includes a newer version of webpack).
Solution 15 - node.js
Running audit fixed the problem for me
npm audit fix --force
Solution 16 - node.js
Same Error with node version v18.0.0 and nuxt framework version 2.15 when running dev server and will be fixed by:
"scripts": {
"dev": "NODE_OPTIONS=--openssl-legacy-provider nuxt"
}
Solution 17 - node.js
I was facing the same issue with Node.js 17.0.1. I solved it by following these steps:
-
Open Control Panel → Program and Features → Node.js and uninstall Node.js by right-clicking a
-
Go to website https://nodejs.org/en/ and download the version and install.
Solution 18 - node.js
Go to:: https://nodejs.org/en/
And download the recommended version for most users.
Then uninstall Node.js from your PC and install the recommended version.
From what I understand, this is a problem from the developer team. They will fix it ASAP, but in the meantime use the recommended version and everything is going to be OK.
Solution 19 - node.js
In Angular.io projects, the accepted (unsupported) version of Nodes.js is v16.x.x.
In Nodes v17.x version, the same error described in this question occurs.
Solution:
Uninstall nodes and reinstall version v16.x (for Windows).
Solution 20 - node.js
Reason:
This error is because node.js 17 uses OpenSSL3, which has changed code for initialization context of md family (including md4), and this is a breaking change. The error can also occur if you build the application using docker build since it pulls the latest version of Node.JS by default.
Install nvm Node Version Manager:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Install latest LTS version:
nvm install --lts
Use LTS version:
nvm use --lts
Done!
Source: https://itsmycode.com/error-digital-envelope-routines-unsupported/
Solution 21 - node.js
Try:
npm create react-app --template typescript foo --use-npm
Solution 22 - node.js
On Dockerfile you should add:
ENV NODE_OPTIONS=--openssl-legacy-provider
Solution 23 - node.js
I have come across this issue today and have resolved it by switching Node.js version using "nvm".
I've been working on a couple of personal projects using Node.js, Next.js, and React... What often happens to me is that I don't remember exactly which version of Node.js do I use for which project.
And so usually I would try to use Node.js 16 for a project that is currently using Node.js 14 (I'm currently on Node.js 17).
I haven't figured out a better way to remember the version of Node.js for each project, so I usually would just save all commands that I need to run to get the application started in readme.MD.
Solution 24 - node.js
You need to update react-scripts to the latest version
npm update react-scripts --save
Solution 25 - node.js
This might not be an answer to the question for everyone. But for anyone running node 17 and above in docker, downgrading just as everyone has said will be helpful. No need for the open-legacy-sslprovider. A simple switch in your Dockerfile from using
From node
to using
From node:16.*
fixes this issue in docker.
Solution 26 - node.js
For Angular app: You can also edit the 'npm start' script in package.json instead > "start": "ng serve -o"
to
> "start": "set NODE_OPTIONS=--openssl-legacy-provider && ng serve -o"
So every time when you run in terminal/command line
npm start
it will first set the NODE_OPTIONS to avoid the problem.
Solution 27 - node.js
In a terminal (OS X), simply downgrade like so:
sudo n 16.13.0
Solution 28 - node.js
fixed by using lts
echo "lts" > .nvmrc
nvm install
Solution 29 - node.js
If you are getting this error while using GatsbyJs, all you need to do is downgrade the node version to long-term support. There is no other salvation
Solution 30 - node.js
Had this issue when using VueJS.
A disadvantage of using -openssl-legacy-provider
is that it is not supported by older Node versions. Older Node versions simply don't run when this flag is provided.
But I still want to be compatible with Node v16 and older.
VueJS uses the md4
algorithm to generate hashes (wel actually it's WebPack under the hood). md4
can be easily replaced by md5
for these kind of purposes. The type of algorithm used, is on most places hard coded, so there's no way to configure another algorithm.
So I came up with another workaround. A function that intercepts the original createHash()
call from the crypto
module and replaces it with a modified version. This is at the start of my vue.config.js
file:
const crypto = require('crypto');
/**
* md4 algorithm is not available anymore in NodeJS 17+ (because of lib SSL 3).
* In that case, silently replace md4 by md5 algorithm.
*/
try {
crypto.createHash('md4');
} catch (e) {
console.warn('Crypto "md4" is not supported anymore by this Node version');
const origCreateHash = crypto.createHash;
crypto.createHash = (alg, opts) => {
return origCreateHash(alg === 'md4' ? 'md5' : alg, opts);
};
}