[Solved] Error message "error:0308010C:digital envelope routines::unsupported"

Article Tarif Hossain

Problem:

Sometimes we are facing following error Error: error:0308010C:digital envelope routines::unsupported in webpack.

Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:67:19)
at Object.createHash (node:crypto:130:10)
at BulkUpdateDecorator.hashFactory (/app/node_modules/webpack/lib/util/createHash.js:155:18)
at BulkUpdateDecorator.update (/app/node_modules/webpack/lib/util/createHash.js:46:50)
at OriginalSource.updateHash (/app/node_modules/webpack-sources/lib/OriginalSource.js:131:8)
at NormalModule._initBuildHash (/app/node_modules/webpack/lib/NormalModule.js:888:17) at handleParseResult (/app/node_modules/webpack/lib/NormalModule.js:954:10)
at /app/node_modules/webpack/lib/NormalModule.js:1048:4
at processResult (/app/node_modules/webpack/lib/NormalModule.js:763:11)
at /app/node_modules/webpack/lib/NormalModule.js:827:5 {
opensslErrorStack: [ ‘error:03000086:digital envelope routines::initialization error’ ],
library: ‘digital envelope routines’,
reason: ‘unsupported’, code: ‘ERR_OSSL_EVP_UNSUPPORTED’
}
command terminated with exit code 1



Solution 1:

If you have this on your package.json - 

{
  "scripts": {
    "build": "next build"
  }
}

Now change it to -

{
  "scripts": {
    "build": "NODE_OPTIONS=--openssl-legacy-provider next build"
  }
}

Now run "npm run build". Hope build will work. If not work then you can run - 


export NODE_OPTIONS=--openssl-legacy-provider


Solution 2: Just run this command in Your terminal.

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


Solution 3: Modify the webpack.config.cjs

module.exports = {
    output: {
        hashFunction: "xxhash64"
    }
};

That's everything you need to know about this issue. Thank you for reading the article.