61

I got this error when learning Next.js, using npx create-next-app command according to site documentation here https://nextjs.org/docs/api-reference/create-next-app. Everything works until I start the server,

Error stack:

$ npm run dev

> devto-clone@0.1.0 dev
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
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 (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
    at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
    at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
    at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
    at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
    at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5
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 (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
    at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
    at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
    at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
    at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
    at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5
node:internal/crypto/hash:67
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

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 (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
    at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
    at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
    at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
    at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
    at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v17.0.1

package.json :

{
  "name": "devto-clone",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "next": "11.1.2",
    "react": "17.0.2",
    "react-dom": "17.0.2"
  },
  "devDependencies": {
    "eslint": "7.32.0",
    "eslint-config-next": "11.1.2"
  }
}
Ruli
  • 2,592
  • 12
  • 30
  • 40
Yuza
  • 2,072
  • 2
  • 10
  • 14

5 Answers5

131

I found this solution https://github.com/webpack/webpack/issues/14532

  1. if using bash just run NODE_OPTIONS=--openssl-legacy-provider before any command

  2. adding NODE_OPTIONS=--openssl-legacy-provider to package.json

    "scripts": {
       "start": "SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
       "build": "SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts build"
     },
    

Edit

In my case, I'm using Nodejs 17.0.1 version and causing this error.

Firstly I'm using this command export NODE_OPTIONS=--openssl-legacy-provider before any command in GitBash Windows to fix this issue.

But, I think it's not an efficient way, so what I do is :

  1. Uninstall Nodejs 17.0.1
  2. Install it again Nodejs 16.13.0 version
  3. I'm facing error another error when I start the server using "yarn serve" (another of my exiting Vuejs project), I don't remember what is this, but after I run "yarn" and "yarn serve", everything works now as I accept
Ruli
  • 2,592
  • 12
  • 30
  • 40
Yuza
  • 2,072
  • 2
  • 10
  • 14
  • Does not work under Win10. I get the error that the command `export` could not be found or is wrongly typed. – Mavv3006 Oct 28 '21 at 19:17
  • Worked for me on Linux. Added the export to my .bashrc for convenience. – raphael Nov 04 '21 at 22:05
  • Thanks for Edit with the last part. Node 16 was the solution for me. – Ricardo Vargas Jan 18 '22 at 20:47
  • @RicardoVargas Windows or Linux? – Erick Adam Apr 25 '22 at 20:41
  • Works for me. Windows 10 NodeJS 17.9.0 Angular 9. On run ng serve: "start": "SET NODE_OPTIONS=--openssl-legacy-provider && ng serve", – Roman Kuznetsov Jun 14 '22 at 10:36
  • 1
    Sorry @ErickAdam, I just saw your message right now. I was using macOS. – Ricardo Vargas Jun 24 '22 at 04:46
  • Thanks, it works "start": "SET NODE_OPTIONS=--openssl-legacy-provider && ng serve" – Sayed Mahmoud Jul 10 '22 at 16:03
  • If you are using Direflow make the script as "set NODE_OPTIONS=--openssl-legacy-provider && direflow-scripts start" – Anshuman Kumar Feb 02 '23 at 15:09
  • This worked for me in a `NextJS` project in a cross-platform (Win/Linux) development situation. Since the prod/deployment env is not Windows, and doesn't exhibit the problem, I created additional `package.json` scripts instead of overriding the defaults, like this: `"scripts": {"dev": "next dev", "dev-win": "SET NODE_OPTIONS=--openssl-legacy-provider && next dev", ... }` – Steverino Feb 27 '23 at 20:10
26

For MacOS and react-native:

"scripts": {
   "start": "NODE_OPTIONS=--openssl-legacy-provider react-native start",
}
Rizvan Rzayev
  • 324
  • 3
  • 6
23

I just got this error, it seems that you are using Node version 17+. It is not compatible with some webpack stuff yet.

Try using LTS version instead, currently at 16.13.0.

  • 4
    Beware that yesterday Node 18 became the [current LTS version](https://github.com/nodejs/Release#release-schedule). If you've pinned your dependency to an LTS tag, the problem might reappear with your next build. – BorysekOndrej Oct 27 '22 at 11:03
  • Node 18.* and webpack are still not compatible as of Feb 2023. The `openssl-legacy-provider` solution above works for this as a workaround if you want to keep Node 18.* features. – Steverino Feb 27 '23 at 20:13
4

This occurred with a build in a docker image when it was using latest node version 17.4.0.

I was able to fix it by switching it to Node v.14 image.

Charith Jayasanka
  • 4,033
  • 31
  • 42
0

If you are using nvm, react native and facing this issue. Try nvm default version 16.13

nvm alias default v16.13.0

This has helped me in removing the error while development. Then I had error in release mode while creating bundle. I figured out the problem, I was using nvm with node 17 as default. After doing,

nvm uninstall v17

the error in release got away.

prisar
  • 3,041
  • 2
  • 26
  • 27
  • 1
    In my case, I had multiple versions. I just uninstalled all of them (nvm uninstall vxx.xx.x) only leaving 1, v16.13.1. After installing the other versions it worked. – user2521166 Jun 17 '22 at 18:19