React npm start webpack Error digital envelope routines unsupported

Running npm start on a newly cloned React project gives the following output errors

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 (C:\workspace\---\node_modules\webpack\lib\util\createHash.js:135:53)
    at NormalModule._initBuildHash (C:\workspace\---\node_modules\webpack\lib\NormalModule.js:417:16)
    at handleParseError (C:\workspace\---\node_modules\webpack\lib\NormalModule.js:471:10)
    at C:\workspace\---\node_modules\webpack\lib\NormalModule.js:503:5
    at C:\workspace\---\node_modules\webpack\lib\NormalModule.js:358:12
    at C:\workspace\---\node_modules\loader-runner\lib\LoaderRunner.js:373:3
    at iterateNormalLoaders (C:\workspace\---\node_modules\loader-runner\lib\LoaderRunner.js:214:10) 
C:\workspace\---\node_modules\react-scripts\scripts\start.js:19
  throw err;
  ^

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 (C:\workspace\---\node_modules\webpack\lib\util\createHash.js:135:53)
Compiled successfully!

Reading through the error you will notes it has something to do with the webpack. But what isn’t clear is that we’re facing a NodeJS versioning issue. The error occurs because of the NodeJS 17+ uses the OpenSSL3. https://wiki.openssl.org/index.php/OpenSSL_3.0#Upgrading_to_OpenSSL_3.0_from_OpenSSL_1.0.2

NodeJS version 17+ is not compatible with webpack version 4. There are at least two ways to solve it. Either downgrade NodeJS or add a legacy parameter.

Solution (keep NodeJS version)

Add legacy provider parameter to your package.json script field.

"start": "react-scripts --openssl-legacy-provider start"

Now when you run ‘npm start’ it’ll use the openssl legacy provider and be able to handle webpack 4.

Solution 2 (downgrade NodeJS)

The more cumbersome approach is downgrading NodeJS to version 16 which is a LTS. https://nodejs.org/en/