66

I am building a Gatsby site. I upgraded Node.js to v17.0.1, and when I run a build, there is an error:

Error: digital envelope routines::unsupported

opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'

If I downgrade it to v16, it works fine, and the build will be successful. How can I fix this?

From googling, this may be a similar issue: Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt #48

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
David
  • 675
  • 1
  • 6
  • 6

13 Answers13

83

This might help. Add these scripts in the package.json file.

React:

"scripts": {
    "start": "export SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
    "build": "export SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts build"
}

or

"scripts": {
    "start": "react-scripts --openssl-legacy-provider start",
    "build": "react-scripts --openssl-legacy-provider build",
}

Vue.js:

"scripts": {
    "serve": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
    "build": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build",
    "lint": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service lint"
},

or

"scripts": {
    "serve": "vue-cli-service --openssl-legacy-provider serve",
    "build": "vue-cli-service --openssl-legacy-provider build",
    "lint": "vue-cli-service --openssl-legacy-provider lint"
},
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Rajiv Singh
  • 1,311
  • 10
  • 29
43

Gatsby must be using an algorithm or key size which is no longer allowed by default with OpenSSL 3.0.

UPDATE ⚠️

This is most likely a webpack issue - https://github.com/webpack/webpack/issues/14532

They have since released a fix in version 5.61.0 - https://github.com/webpack/webpack/releases/tag/v5.61.0 - so upgrading webpack should address the issue as well

A member of the webpack team has stated they do not plan to backport the fix to webpack 4, so if you are on webpack 4 you may need to look to upgrading to webpack 5 first.


From Node.js 17's announcement post:

If you hit an ERR_OSSL_EVP_UNSUPPORTED error in your application with Node.js 17, it’s likely that your application or a module you’re using is attempting to use an algorithm or key size which is no longer allowed by default with OpenSSL 3.0. A new command-line option, --openssl-legacy-provider, has been added to revert to the legacy provider as a temporary workaround for these tightened restrictions.

Running this on the terminal might look like:

node --openssl-legacy-provider ./node_modules/.bin/gatsby build

You can also pass this in via the NODE_OPTIONS environment variable.

So if you'd like to continue using the NPM script, you can change the build script to:

// package.json
{
  "scripts": {
    "build": "export NODE_OPTIONS=--openssl-legacy-provider; gatsby build"
  }
}
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
romellem
  • 4,222
  • 1
  • 32
  • 59
  • This command does get rid of the error: node --openssl-legacy-provider ./node_modules/.bin/gatsby build Thanks a lot! Does it mean that it is down to Gatsby team (or even any modules it depends) to fix the issue in future? – David Oct 21 '21 at 16:15
  • 1
    Yes, from the error you posted, I can't be sure if it is gatsby directly or a module they are consuming. I imagine they'll have a bugfix release for this in the near future. – romellem Oct 21 '21 at 20:18
34

Quick fix: Run this in a terminal inside your React project.

export NODE_OPTIONS=--openssl-legacy-provider
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Byusa
  • 745
  • 9
  • 14
  • 2
    worked here with node v17 for Mastodon server. Thx! – MegaTux Dec 01 '21 at 14:26
  • 2
    Where does that go? In a script file? Manually in a terminal? When should it be applied? In what context? What should be run afterwards in that terminal? What do you mean by *"Run this in a terminal inside your React project"*? In what environment? In a [Visual Studio Code](https://en.wikipedia.org/wiki/Visual_Studio_Code) context? Something else? Can you elaborate? Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/70116509/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jan 04 '22 at 23:55
  • @PeterMortensen Run this in a terminal inside your React project. eg: ```cd book_react_app``` ```export NODE_OPTIONS=--openssl-legacy-provider``` @PeterMortensen Can you suggest an edit if this is not clear? Thank you – Byusa Jan 05 '22 at 21:26
  • node: --openssl-legacy-provider is not allowed in NODE_OPTIONS – Krishnadas PC May 25 '22 at 17:49
9

I also had the same problem, so I just degraded the Node.js version:

  • Uninstall Node.js

  • Then download and install 16.13.0.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
6

This issue comes with the new update of Node.js 17. In React you can change the script attribute in the package.json file to:

"scripts": {
    "start": "react-scripts --openssl-legacy-provider start",
    "build": "react-scripts --openssl-legacy-provider build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
}
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
4

I think there are two solutions for this error we encountered after the new Node.js update.

  1. Downgrade Node.js

  2. node_modules\react-scripts\config\webpack.config.js - you should add this code inside the .js file you find here:

        const crypto = require("crypto");
        const crypto_orig_createHash = crypto.createHash;
        crypto.createHash = algorithm => crypto_orig_createHash(algorithm == "md4" ? "sha256" : algorithm);
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
lestonz
  • 41
  • 2
  • none of the downgrade/export fixes worked! but this worked for me. i think ill use this fix temporarily until I reinstall my OS (it happened after I upgraded to fedora 36). – ctrleffive May 11 '22 at 06:29
3

Rajiv's approach seems right as a workaround, but the syntax didn't worked for me in Vue.js. What worked was without the keyword "SET":

  "scripts": {
    "serve": "NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
    "build": "NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build",
    "test:unit": "NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service test:unit",
    "lint": "NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service lint"
  },
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
dakockar
  • 31
  • 5
3

I have uninstalled my Node.js version 17.0.1 through the control panel.

Then I downloaded the Node.js version 16.13.1 from the nodejs.org and installed it, and then React Native starts and builds fine.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
3

I have faced this similar issue in the version 17.3.0

  1. I have uninstalled Node.js and installed the version to 16.13.0 and restarted
  2. by running in the new terminal ,it got fixed
hema
  • 31
  • 3
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30745970) – bguiz Jan 10 '22 at 02:43
1

I was facing the same issue with an Angular application on server -

  1. I just downgraded the Node.js version locally to 14
  2. The Docker image replaced with version 14.18.1. Earlier it was Alpine Linux

You can find more details in Node.js' latest release documentation.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
neekheel
  • 132
  • 1
  • 17
0

Use it as build command for Vue 3 and node v17.0.1:

cross-env NODE_OPTIONS='--openssl-legacy-provider' vue-cli-service build"
rink.attendant.6
  • 40,889
  • 58
  • 100
  • 149
0

While patching with --openssl-legacy-provider is more of a hack and a real solution would be to fix OpenSSL key size usage in Vue/React/...; a temporal workaround may be using elder version of Node indeed. But I'd suggest not to downgrade Node; rather install NVM (main/win: nvm-windows/nodist/nvs, the last one being cross-platform) and switch between versions on demand.

YakovL
  • 6,451
  • 11
  • 52
  • 82
0

i think you should downgrade your node or use nvm to switch between node versions, i did this and the react worked fine

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 13 '22 at 19:17