ERROR: Error:0308010c:Digital Envelope Routines::Unsupported

The error: error:0308010c:digital envelope routines::unsupported is usually seen when making a react application with Node.JS version 17 or higher and webpack@4 version.

Web development has come a long way since the early days of HTML, CSS, and PHP pages. There are a lot of web development frameworks that we can use to make apps and websites quickly.

In this tutorial we will know what is error:0308010c:digital envelope routines::unsupported and how to fix this issue.

error: error:0308010c:digital envelope routines::unsupported
How To Fix Error

What is error:0308010c:digital envelope routines::unsupported ?

We run into the following problem when setting up and running the React project with the latest version of Node.JS 17 or higher.

Nodejs 17: digital envelope routines::unsupported

[webpack-cli] Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:130:10)
    at BulkUpdateDecorator.hashFactory (/opt/src/node_modules/webpack/lib/util/createHash.js:155:18)
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'

The error can also happen if you use docker build to build the app, since it automatically gets the latest version of Node.JS.

This error happens because node.js 17 uses OpenSSL3, which has changed the code for initialization context of md family (including md4), which is a breaking change.

Version 17 of Node JS is not LTS (Long Term Support), and it is not compatible with version 4 of webpack.

How To Resolve error: error:0308010c:digital envelope routines::unsupported?

There are many ways to fix the problem. Let’s look at each one of these ideas.

First Solution: Add the legacy OpenSSL in package.json

If you still want to use Node.js 17 or above, you can go to package.json and change the line to fix the problem.

From:

"start": "react-scripts start"

To:

"start": "react-scripts --openssl-legacy-provider start"

Changing this package script.json makes Node.js use OpenSSL 3 in the legacy mode, which means you are using algorithms that are known to be insecure.

Second Solution: Downgrade Node.JS to Long Term Support(LTS)

The other way to fix the problem is to roll back Node.JS to version 16.14.0 of the LTS release.

There are many different ways to install and use versions of Node.js. One of the best ways to handle different versions of Node is to use Node Version Manager.

Step 1: Install the Node Version manager using the below command.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Step 2: You can install the specific node.js version or just use the below command to install the node.js LTS version.

nvm install --lts

Step 3: Set the node.js to use the latest LTS version using the following command.

nvm use --lts

For the Docker build, you can change the DockerFile in a way that looks like this.

From:

...
FROM node:alpine
...

To:

...
FROM node:16-alpine3.12
...

Third Solution: Setting openssl-legacy-provider Globally

Setting the NODE_OPTIONS is not a good idea, but you can still try it as a quick fix on your own machine.

With the Docker build, you can try the same thing. To fix the problem, all you have to do is add the line below to your DockeFile.

RUN export NODE_OPTIONS=--openssl-legacy-provider && yarn build && yarn install --production --ignore-scripts --prefer-offline

Conclusion

The error: error:0308010C:digital envelope routines::unsupported happens in Node.js version 17 because it’s not the LTS version and because OpenSSL changed in a way that breaks older versions.

We can fix the problem by either downgrading Node.js to LTS (16.14.0) or making changes to the package.json start script to “start”: “react-scripts –openssl-legacy-provider start”

Recommendations

Inquiries

However, If you have any questions about on how to fix this error: error:0308010c:digital envelope routines::unsupported, Please feel free to comment below, Thank You and God Bless!

Leave a Comment