Error: error:0308010C:digital envelope routines::unsupported
Asked Answered
R

9

22

I have been trying to deploy my nuxt app to Vercel for a while now but I'm getting this error saying: Error: error:0308010C:digital envelope routines::unsupported

I solved the issue on my local machine downgrading my node.js to 16+ but this still occurs in the production environment. I tried to set the --openssl-legacy-provider to the scripts object in my package.json but it had no effect. ps. I'm not so sure if the syntax was correct since most of the answers were for react.

Here's the whole 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 (/vercel/path0/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/vercel/path0/node_modules/webpack/lib/NormalModule.js:417:16)
    at handleParseError (/vercel/path0/node_modules/webpack/lib/NormalModule.js:471:10)
    at /vercel/path0/node_modules/webpack/lib/NormalModule.js:503:5
    at /vercel/path0/node_modules/webpack/lib/NormalModule.js:358:12
    at /vercel/path0/node_modules/webpack/node_modules/loader-runner/lib/LoaderRunner.js:373:3
    at iterateNormalLoaders (/vercel/path0/node_modules/webpack/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
    at Array.<anonymous> (/vercel/path0/node_modules/webpack/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
    at Storage.finished (/vercel/path0/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
    at /vercel/path0/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
    at /vercel/path0/node_modules/graceful-fs/graceful-fs.js:123:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}
Node.js v18.12.1
Error: Command failed with exit code 1: npx nuxt build --standalone --no-lock --config-file "nuxt.config.js" /vercel/path0

My package.json:

{
  "name": "my-project",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate"
  },
  "dependencies": {
    "@nuxtjs/axios": "^5.13.6",
    "@nuxtjs/vercel-builder": "^0.24.0",
    "@nuxtjs/vuetify": "^1.12.3",
    "@stripe/stripe-js": "^1.46.0",
    "cookie-parser": "^1.4.6",
    "cookieparser": "^0.1.0",
    "cors": "^2.8.5",
    "express": "^4.18.2",
    "gsap": "npm:@gsap/shockingly@^3.11.3",
    "nuxt": "^2.14.6",
    "nuxt-gsap-module": "^1.7.2",
    "stripe": "^11.3.0",
    "vuex-persistedstate": "^4.1.0"
  }
}
Raster answered 14/12, 2022 at 11:39 Comment(0)
P
29

Run this command to fix the issue:

export NODE_OPTIONS=--openssl-legacy-provider
Pontiac answered 13/4, 2023 at 19:23 Comment(2)
Thanks for sharing. it saved me some time. However, can you explain what this does exactly?Fathomless
Hi, the --openssl-legacy-provider flag is used to specify that Node.js should use the legacy OpenSSL provider instead of the default provider that comes with newer versions of Node.js. This flag is typically necessary when using certain libraries or dependencies that require compatibility with the older OpenSSL version.Frumpy
R
19

I got it working by defining the node.js version in the package.json like this:

"engines": {
  "node": "16.x"
},
Raster answered 14/12, 2022 at 14:34 Comment(5)
This fixed the production error? Interesting. I guess that Vercel detects it and can handle that itself, even if you don't force a specific version there.Leonor
Thank you! This fixed my production error.Melee
@Nicolas, This - https://mcmap.net/q/44955/-error-message-quot-error-0308010c-digital-envelope-routines-unsupported-quot - answer strongly cautions against downgrading Node.js to pre v17 or to using the legacy SSL provider. Both of those solutions are hacks that leave your builds open to security threats.Camlet
Yes this works, vercel will honor engines and override the settings on their website vercel.com/docs/concepts/functions/serverless-functions/…Deathbed
Node 16 is deprecated in August of 2023, so this won't work for longCuttler
A
6

This solution will work:

webpack.config.js:

const path = require("path");
const crypto = require("crypto");
const crypto_orig_createHash = crypto.createHash;
crypto.createHash = algorithm => crypto_orig_createHash(algorithm == "md4" ? "sha256" : algorithm);

module.exports = {
  entry: "./src/index.js",
  output: {
    filename: "app.js",
    hashFunction: "sha256",
    path: path.resolve(__dirname, "dist")
  },
  devServer: {
    contentBase: path.join(__dirname, "dist"),
    port: 9000
  },
  mode: "development"
};
Ashtonashtonunderlyne answered 15/8, 2023 at 9:34 Comment(2)
I used the top portion, and it fixed! I tried many of the others including npm audit, node upgrade, webpack upgrade, and even the hashFunction change, but adding this to webpack config even with Neutrino JS worked great! Love this guy!Builder
This is the best solution. Other solutions (downgrading Node or using --openssl-legacy-provider) may expose you to vulnerabilities.Filaria
S
5

I am getting same error below solution works for me:

You can execute this command on your root level of project or just open your terminal and run.

set NODE_OPTIONS=--openssl-legacy-provider

Before:

enter image description here

After

enter image description here

Shardashare answered 27/4, 2023 at 5:56 Comment(0)
P
4
  1. Set NODE_OPTIONS Environment Variable:

    • Unix-like (Linux, macOS, Git bash, etc.):

      export NODE_OPTIONS=--openssl-legacy-provider
      
    • Windows Command Prompt:

      set NODE_OPTIONS=--openssl-legacy-provider
      
    • PowerShell:

      $env:NODE_OPTIONS = "--openssl-legacy-provider"
      
    • Additionally, integrate these into scripts in your package.json:

      "scripts": {
        "start": "export NODE_OPTIONS=--openssl-legacy-provider && ng serve" // use set instead of export in case of windows machine
      }
      
    • Alternatively, install cross-env globally (npm install --global cross-env) and use it in your scripts:

      "scripts": {
        "start": "cross-env NODE_OPTIONS=--openssl-legacy-provider && ng serve"
      }
      
  2. Set SSL Legacy Option via NPM:

    • For a simpler approach through NPM, set the SSL legacy option in the .npmrc file.

      • Example for NodeJS v18 with npm v9:
        • Add or edit .npmrc file in your project folder and include the option:
          node-options="--openssl-legacy-provider"
          
    • Advantages:

      • This setting can be managed per project.
      • The .npmrc file in the project will serve as a reminder for necessary updates.
      • If the issue occurs in other projects on the server, the error will be addressed consistently.
Palermo answered 11/12, 2023 at 15:43 Comment(0)
K
3

I had the same issue and I solve it by doing this: In your pakage.json file put these two lines and then your error will be solved.

"scripts": {
"start": "react-scripts --openssl-legacy-provider start",
"build": "react-scripts --openssl-legacy-provider build",
}
Krispin answered 6/4, 2023 at 20:7 Comment(1)
you saved my life, i was scratching my head for 2h..Enrico
S
2

Works as of 10/2023...

In Vercel Environment Variables...

Variable: NODE_OPTIONS
Value: --openssl-legacy-provider

Sphenic answered 2/10, 2023 at 19:34 Comment(1)
Following this action, I encounter a 500 error, and the logs on Vercel indicate the following issue: "--openssl-legacy-provider is not permitted in NODE_OPTIONS."Gaitskell
S
0

What I did is I updated the react-script to 5.0.0 in package.json, deleted the package.lock.json and node_modules then I did npm install in the terminal.

source: https://www.freecodecamp.org/news/error-error-0308010c-digital-envelope-routines-unsupported-node-error-solved/

Selinski answered 25/2, 2023 at 8:46 Comment(0)
G
0

I resolve it's problem add this options in package.json:

"engines": {
  "node": "18.x"
},

"scripts": {
  "start": "react-scripts --openssl-legacy-provider start",
  "build": "react-scripts --openssl-legacy-provider build",
}
Gannon answered 11/6, 2023 at 17:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.