Yusuf
Yusuf

Reputation: 3483

Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:71:19)

after building my react docker image I tried to run docker run image_name and after that the log throw this error

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (/app/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/app/node_modules/webpack/lib/NormalModule.js:417:16)
    at /app/node_modules/webpack/lib/NormalModule.js:452:10
    at /app/node_modules/webpack/lib/NormalModule.js:323:13
    at /app/node_modules/loader-runner/lib/LoaderRunner.js:367:11
    at /app/node_modules/loader-runner/lib/LoaderRunner.js:233:18
    at context.callback (/app/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at /app/node_modules/babel-loader/lib/index.js:59:103 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

my docker file is as follows

FROM node:18-alpine
EXPOSE 3000
WORKDIR /app
COPY ./frontend/package.json .
RUN npm install
COPY ./frontend .
COPY ./images .
CMD ["npm", "start"]

I am expecting this might be a node version issue, but I am not quite sure about the error, can anybody explain what this error is about and how I can resolve? thanks

Upvotes: 52

Views: 168208

Answers (13)

Tejas Shiwankar
Tejas Shiwankar

Reputation: 1

just do this Modify your package.json and add the NODE_OPTIONS setting in the scripts: For Windows users, modify it as:

"start": "set NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
"build": "set NODE_OPTIONS=--openssl-legacy-provider && react-scripts build"

Then, try running:

npm start

Upvotes: 0

Henry Nnonyelu
Henry Nnonyelu

Reputation: 64

On your Vs code Terminal. Enter the following:

$env:NODE_OPTIONS = "--openssl-legacy-provider"

npm run start

and press enter key

Upvotes: 1

Audwin Oyong
Audwin Oyong

Reputation: 2531

The cause is that before Node 17.x versions, It uses OpenSSL 2 version. NodeJS uses OpenSSL for hash functionality code. The OpenSSL 3 disables MD4, hence Node.js is broken in the latest Node.js versions.

Node.js v17 moved to OpenSSL v3.0.

For Next.js / TypeScript project, I have to change the following dev script to use the legacy provider in package.json for it to work:

"scripts": {
  "dev": "next dev",
  ...
},

To be:

"scripts": {
  "dev": "node --openssl-legacy-provider ./node_modules/.bin/next dev",
  ...
},

Or with start script:

"scripts": {
  "start": "next",
  ...
},

To be:

"scripts": {
  "start": "node --openssl-legacy-provider ./node_modules/.bin/next",
  ...
},

Upvotes: 1

davecardwell
davecardwell

Reputation: 4218

Node.js v17 moved to OpenSSL v3.0.

You could try switching to v16, or set ENV NODE_OPTIONS="--openssl-legacy-provider" in your Dockerfile, or update your start script in package.json to use react-scripts --openssl-legacy-provider start (or similar depending on your specific start script).

There is an issue you can follow here: https://github.com/facebook/create-react-app/issues/11708

Upvotes: 48

Fred Ondieki
Fred Ondieki

Reputation: 2514

Cause

Before Node 17.x versions, It uses OpenSSL 2 version. NodeJS uses OpenSSL for hash functionality code. The OpenSSL 3 disables MD4, Due to that Nodejs is broken in the latest Nodejs versions.

Solution

  1. Linux users:
export NODE_OPTIONS=--openssl-legacy-provider
  1. Windows users:
set NODE_OPTIONS=--openssl-legacy-provider
  1. You can add: NODE_OPTIONS=--openssl-legacy-provider to npm scripts.

Upvotes: 14

shiraz27
shiraz27

Reputation: 2656

You can simply use node v16, try NVM for switching between versions easily.

Upvotes: 4

information_interchange
information_interchange

Reputation: 3128

So, I was running npm run dev to do my development, and my package.json looked like:

 "scripts": {
    "dev": "next dev",
...

So, I changed that line to:

  "scripts": {
    "dev": "node --openssl-legacy-provider ./node_modules/.bin/next dev",

and it worked like a charm.

Upvotes: 3

marcvander
marcvander

Reputation: 649

I had the same problem on Heroku. During the build phase, I got the same error. To solve it, I just had to set as an environment variable:

NODE_OPTIONS="--openssl-legacy-provider"

Upvotes: 17

ravi Verma
ravi Verma

Reputation: 281

To start your application:

update your start script in package.json to use

react-scripts --openssl-legacy-provider start

To build your application:

update your build script in package.json to use

react-scripts --openssl-legacy-provider build

Upvotes: 28

Naod Agere
Naod Agere

Reputation: 59

This error happened to me after installing the latest Node version/18.15 on my machine while using angular v 12.2.14. So, I was supposed to uninstall the latest node and downgrade it to an older version/v14.21.3 which is compatible with the angular version. Used : https://unpkg.com/browse/@angular/[email protected]/package.json for compatibility check.

Upvotes: 1

valter mendes
valter mendes

Reputation: 109

After a deep search I come up with this solution.

What was the issue? The issue was the difference between my Node Version and React js version.

Node.js v18.4.0
"react":"^16.12.0"

Solution:

  1. Make Sure that you have nvm installed in you machine if you don't here is the link Node Version Manager
  2. In your Project terminal type: nvm ls (You should see a list as showed below ) nvm ls
  3. Type : nvm use v16.15.1 choose a version that fits you

If you don't have any nvm installed

Note: After install nvm You MUST RESTART THE TERMINAL OR CLOSE AND OPEN in order to see nvm version

Upvotes: 5

Igor Mitrinovic
Igor Mitrinovic

Reputation: 27

Check package.json, under the script I have,

"scripts": { "start": "expo start", "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web" }

in terminal run

expo start -web

Upvotes: -2

Yusuf
Yusuf

Reputation: 3483

I changed node version node:16.3.0-alpine and it worked however can any body explain digital envelope routines please

Upvotes: 0

Related Questions