Node.js 17.0.1 Gatsby error - "digital envelope routines::unsupported ... ERR_OSSL_EVP_UNSUPPORTED"

node.jsGatsby

node.js Problem Overview


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

node.js Solutions


Solution 1 - node.js

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"
},

Solution 2 - node.js

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"
  }
}

Solution 3 - node.js

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

export NODE_OPTIONS=--openssl-legacy-provider

Solution 4 - node.js

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

  • Uninstall Node.js

  • Then download and install 16.13.0.

Solution 5 - node.js

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"
}

Solution 6 - node.js

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);
    

Solution 7 - node.js

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"
  },

Solution 8 - node.js

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.

Solution 9 - node.js

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

Solution 10 - node.js

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.

Solution 11 - node.js

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

cross-env NODE_OPTIONS='--openssl-legacy-provider' vue-cli-service build"

Solution 12 - node.js

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.

Solution 13 - node.js

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDavidView Question on Stackoverflow
Solution 1 - node.jsRajiv SinghView Answer on Stackoverflow
Solution 2 - node.jsromellemView Answer on Stackoverflow
Solution 3 - node.jsByusaView Answer on Stackoverflow
Solution 4 - node.jsVivek Raj SinghView Answer on Stackoverflow
Solution 5 - node.jsKautuk DwivediView Answer on Stackoverflow
Solution 6 - node.jslestonzView Answer on Stackoverflow
Solution 7 - node.jsdakockarView Answer on Stackoverflow
Solution 8 - node.jsuser17670454View Answer on Stackoverflow
Solution 9 - node.jshemaView Answer on Stackoverflow
Solution 10 - node.jsneekheelView Answer on Stackoverflow
Solution 11 - node.jsSanny ZaycevView Answer on Stackoverflow
Solution 12 - node.jsYakovLView Answer on Stackoverflow
Solution 13 - node.jsJojo CodesView Answer on Stackoverflow