8

I have been trying to deploy my nuxt app to Vercel for a few days 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"
  }
}
kissu
  • 40,416
  • 14
  • 65
  • 133
Nicolas
  • 434
  • 1
  • 3
  • 13

7 Answers7

16

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

"engines": {
  "node": "16.x"
},
kissu
  • 40,416
  • 14
  • 65
  • 133
Nicolas
  • 434
  • 1
  • 3
  • 13
  • 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. – kissu Dec 14 '22 at 14:35
  • 2
    Thank you! This fixed my production error. – Charles Ouverleaux Jan 04 '23 at 20:50
  • 1
    @Nicolas, This - https://stackoverflow.com/a/73027407/1459653 - 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. – Mark Gavagan Jan 11 '23 at 18:23
  • Yes this works, vercel will honor engines and override the settings on their website https://vercel.com/docs/concepts/functions/serverless-functions/runtimes/node-js#node.js-version – Rachid Boudjelida Mar 30 '23 at 17:00
  • Node 16 is deprecated in August of 2023, so this won't work for long – Jan Jun 24 '23 at 01:20
13

Run this command to fix the issue:

export NODE_OPTIONS=--openssl-legacy-provider
Taady
  • 2,409
  • 2
  • 10
  • 24
  • Thanks for sharing. it saved me some time. However, can you explain what this does exactly? – Solomon Sunday May 11 '23 at 16:08
  • 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. – Taady May 11 '23 at 17:36
4

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

Abdullah
  • 2,393
  • 1
  • 16
  • 29
1

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",
}
jozef koko
  • 82
  • 5
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/

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",
}
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
-1

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"
};
Tyler2P
  • 2,324
  • 26
  • 22
  • 31