Error with NodeJS 17 and WebPack 5.5.0 -  error:0308010C:digital envelope routines::unsupported

When trying to setup a project with Next.JS, WebPack 5.5.0 and NodeJS 17 I have hit a bug related to a change of the OpenSSL library from version 1.0

I started Next.js with:

$ yarn dev

 And I got this error:

info — Using webpack 5. Reason: Enabled by default
bffHost some-hostname
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 (/mnt/c/./node_modules/next/dist/compiled/webpack/bundle5.js:138971:18)
at BulkUpdateDecorator.update (/mnt/c/./node_modules/next/dist/compiled/webpack/bundle5.js:138872:50)
at OriginalSource.updateHash (/mnt/c/./node_modules/next/dist/compiled/webpack-sources3/index.js:1:10264)
at NormalModule._initBuildHash (/mnt/c/./node_modules/next/dist/compiled/webpack/bundle5.js:68468:17)
at handleParseResult (/mnt/c/./node_modules/next/dist/compiled/webpack/bundle5.js:68534:10)
at /mnt/c/./node_modules/next/dist/compiled/webpack/bundle5.js:68628:4
at processResult (/mnt/c/./node_modules/next/dist/compiled/webpack/bundle5.js:68343:11)
at /mnt/c/./node_modules/next/dist/compiled/webpack/bundle5.js:68407:5

After some research, I found a StackOverflow post and a webpack GitHub issue related to this error. nodejs 17: digital envelope routines::unsupported · Issue #14532 · webpack/webpack
You can’t perform that action at this time. You signed in with another tab or window. You signed out in another tab or…

It’s already fixed in a more recent version of webapack. It was due to an upgrade of the OpenSSL library in NodeJS 17.

As a workaround in the same Github issue recommends running:

$ export NODE_OPTIONS=--openssl-legacy-provider
$ yarn dev

I have tried this and it works!


Github Issue

Stackoverflow with resoluton