question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-scripts fails to build project with Node 17

See original GitHub issue

Describe the bug

we have a CRA app, it used to build with Node 14.x very fine, today I upgrade nodejs to 17.0.0 and it failed. (in both my local machine and the CI-CD machine)

And these were the logs:

> react-scripts build
Creating an optimized production build...
Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:130:10)
    at module.exports (/my-project/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/my-project/node_modules/webpack/lib/NormalModule.js:417:16)
    at handleParseError (/my-project/node_modules/webpack/lib/NormalModule.js:471:10)
    at /my-project/node_modules/webpack/lib/NormalModule.js:503:5
    at /my-project/node_modules/webpack/lib/NormalModule.js:358:12
    at /my-project/node_modules/loader-runner/lib/LoaderRunner.js:373:3
    at iterateNormalLoaders (/my-project/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
    at iterateNormalLoaders (/my-project/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
    at /my-project/node_modules/loader-runner/lib/LoaderRunner.js:236:3
    at runSyncOrAsync (/my-project/node_modules/loader-runner/lib/LoaderRunner.js:130:11)
    at iterateNormalLoaders (/my-project/node_modules/loader-runner/lib/LoaderRunner.js:232:2)
    at Array.<anonymous> (/my-project/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
    at Storage.finished (/my-project/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
    at /my-project/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
/my-project/node_modules/react-scripts/scripts/build.js:19
  throw err;
  ^
Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:130:10)
    at module.exports (/my-project/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/my-project/node_modules/webpack/lib/NormalModule.js:417:16)
    at /my-project/node_modules/webpack/lib/NormalModule.js:452:10
    at /my-project/node_modules/webpack/lib/NormalModule.js:323:13
    at /my-project/node_modules/loader-runner/lib/LoaderRunner.js:367:11
    at /my-project/node_modules/loader-runner/lib/LoaderRunner.js:233:18
    at context.callback (/my-project/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at /my-project/node_modules/babel-loader/lib/index.js:59:103 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}
Node.js v17.0.0
ERROR: Job failed: exit status 1

Did you try recovering your dependencies?

yes. in both local machine and CI-CD machine I re-installed all the dependencies

Which terms did you search for in User Guide?

I searched Google for error:0308010C:digital envelope routines::unsupported with and without the 0308010C part

Environment

current version of create-react-app: 4.0.3
  running from /home/.npm/_npx/34113/lib/node_modules/create-react-app

  System:
    OS: Linux 5.13 Ubuntu 21.10 21.10 (Impish Indri)
    CPU: (4) x64 Intel(R) Core(TM) i5-4460  CPU @ 3.20GHz
  Binaries:
    Node: 17.0.0 - /usr/bin/node
    Yarn: Not Found
    npm: 8.1.0 - /usr/bin/npm
  Browsers:
    Chrome: 95.0.4638.54
    Firefox: 93.0
  npmPackages:
    react: ^16.13.1 => 16.13.1 
    react-dom: ^16.13.1 => 16.13.1 
    react-scripts: ^4.0.3 => 4.0.3 
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

(Write your steps here:)

  1. create new react app with create-react-app and node 14
  2. do npm run build to see it builds completely fine
  3. upgrade to node 17 and do npm run build again to see it fail

Expected behavior

to build flawlessly

Actual behavior

The build failed with errors printed above!

Note

I know that it is mostly not related to create-react-app, but another package, maybe webpack or it’s dependencies. But as I cannot dig down, I write this issue here so the professionals can track it further.

Thanks

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:27
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
trashcodercommented, Oct 22, 2021

in your package.json: change this line "build": "react-scripts start", to "build": "react-scripts --openssl-legacy-provider build",

9reactions
KiraLTcommented, Dec 21, 2021

If you need to support both 17 and older NodeJS versions you can use if-node-version to execute different commands for different NodeJS versions:

{
    "scripts": {
        "build": "if-node-version '>= 17' && react-scripts --openssl-legacy-provider build || react-scripts build",
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

My create-react-app is failing to compile due to ESLint error
1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder. 2. Delete node_modules in your project folder. 3.
Read more >
react-scripts - npm
Configuration and scripts for Create React App.. ... Start using react-scripts in your project by running `npm i react-scripts`.
Read more >
How to fix build failures with `create-react-app` in production
The build script bootstrapped by create-react-app performs some validation of your code. When most of this validation fails, ...
Read more >
error:0308010c:digital envelope routines::unsupported - You ...
In my case this error is usually because of node v17 vs. webpack which usually works fine with node v16 . Did you...
Read more >
How to Fix the Error Error:error:0308010C:digital envelope ...
With Node.js v17+ supporting OpenSSL 3.0, algorithms like MD4 have ... For an older Create React App project that runs react-script v4.0.3 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found