Creating REST API Endpoints / errors in installation

I’m in the project Creating REST API Endpoints and following the instructions, very simple, just download, npm install and npm run start in each sub-folder for the project.

But I’m having these errors when starting the front end; I’ve tried to figure out changing react-scripts versions and also installing most recent version of webpack but didnt work.

Does anybody knows what it could be?

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:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\node_modules\webpack\lib\util\createHash.js:135:53)
at NormalModule._initBuildHash (C:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\node_modules\webpack\lib\NormalModule.js:417:16)
at handleParseError (C:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\node_modules\webpack\lib\NormalModule.js:471:10)
at C:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\node_modules\webpack\lib\NormalModule.js:503:5
at C:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\node_modules\webpack\lib\NormalModule.js:358:12
at C:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\node_modules\loader-runner\lib\LoaderRunner.js:373:3
at iterateNormalLoaders (C:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
at iterateNormalLoaders (C:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\node_modules\loader-runner\lib\LoaderRunner.js:221:10)
C:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\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:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\node_modules\webpack\lib\util\createHash.js:135:53)
at NormalModule._initBuildHash (C:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\node_modules\webpack\lib\NormalModule.js:417:16)
at C:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\node_modules\webpack\lib\NormalModule.js:452:10
at C:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\node_modules\webpack\lib\NormalModule.js:323:13
at C:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\node_modules\loader-runner\lib\LoaderRunner.js:367:11
at C:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\node_modules\loader-runner\lib\LoaderRunner.js:233:18
at context.callback (C:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
at C:\Users\guhen\Downloads\creating-rest-api (1)\creating-rest-api\starting-code\frontend\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’
}

1 Like

Same problem here. It has something to do with outdated versions maybe. If you found a solution please share.

I’m a ways off from this project but it’s in my path so I invested a bit of time looking into this… Apparently the issue is that Webpack defaults to MD4 for its hashing algorithm, which is no longer supported by OpenSSL (and shouldn’t be). This is causing the errors in node:crypto which is a node module acting as a wrapper for OpenSSL hash functions (and others).

Try adding these lines into the file frontend/node_modules/react-scripts/config/webpack.config.js

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

I tested this out and after seeing the error you described, it is no longer being reported (although I am getting other errors due to missing components - but they seem to be because I haven’t done any of the steps in the project).

Edit: other solutions online mention downgrading your Node.js version and/or using legacy versions of OpenSSL. This is a bad idea in general for any project as it introduces security vulnerabilities.

1 Like

I ran into this today and spend some time fixing it. The backend seems fine and should be installed and started as normal, but here is my procedure to fix the frontend:

  1. Unzip the starting-code/frontend directory from create-rest-api.zip
  2. Edit the package.json file
  • Delete the dependency for “react-event-calendar”. This package is deprecated and not used anywhere in the current code. It is replaced by “react-big-calendar” which already exists in the dependency list.
  • Remove all the versions from every dependency. Leave them all with just empty quotes. i.e. “”
  • Add the following dependecies to the list:
    @mui/x-date-pickers”: “”,
    “date-fns”: “”,
  • Modify the “start” line under scripts to include:
    Windows: “start”: “set PORT=3001 && react-scripts start”
    Linux: “start”: “PORT=3001 react-scripts start”
  1. Edit the file “src/components/Booklist.js”:
  • On line 2, capitalize the word calendar. “import CalendarComponent from ‘./Calendar’;”
  • Replace lines 13, 14, and 15 with the following:
    import { AdapterDateFns } from ‘@mui/x-date-pickers/AdapterDateFns’
    import { LocalizationProvider, DatePicker } from ‘@mui/x-date-pickers’;
  1. Run npm install
  2. Run npm update
  3. Run npm start

When the browser tab opens, I am presented with a giant calendar and form to add a new book to read. It runs without errors, just deprecation warnings. Now I haven’t done anything else with it yet so I don’t know if I will encounter problems following the project procedure steps, but for now it is up and running.

Just a follow-up. I finished the project and everything worked just fine after doing the above modifications.

Yes that fixed the issue. Thank you very much!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.