Nodejs 17 breaks webpack 5
Nodejs 17 upgrades to OpenSSL 3.0, which removes the md4
hashing function that webpack 5 uses for hashing files.
To fix this, you can provide an alternative hashing function for webpack to use. Set output.hashFunction: 'xxhash64'
in the webpack config. See: https://stackoverflow.com/a/73027407/2214847
However, setting this option does not fix the issue in our case, since react-pdf/dist/esm/entry.webpack.js
loads its files via an unconfigurable file-loader
, which uses the default md4
...
See log files
ERROR in ./node_modules/pdfjs-dist/legacy/build/pdf.worker.js (./node_modules/file-loader/dist/cjs.js!./node_modules/pdfjs-dist/legacy/build/pdf.worker.js)
Module build failed (from ./node_modules/file-loader/dist/cjs.js):
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:71:19)
at Object.createHash (node:crypto:133:10)
at getHashDigest (/home/hugo/Documents/zesje/node_modules/file-loader/node_modules/loader-utils/lib/getHashDigest.js:46:34)
at /home/hugo/Documents/zesje/node_modules/file-loader/node_modules/loader-utils/lib/interpolateName.js:113:11
at String.replace (<anonymous>)
at interpolateName (/home/hugo/Documents/zesje/node_modules/file-loader/node_modules/loader-utils/lib/interpolateName.js:110:8)
at Object.loader (/home/hugo/Documents/zesje/node_modules/file-loader/dist/index.js:29:48)
@ ./node_modules/react-pdf/dist/esm/entry.webpack.js 3:0-73 9:38-49
@ ./client/views/AddExam.jsx 38:0-66 168:44-48 263:42-50
@ ./client/App.jsx 56:9-38
@ ./client/index.jsx 13:0-28 22:43-46
So to fix this, we should both:
- Set
output.hashFunction: 'xxhash64'
in the webpack config to fix the general case - Use an alternative wrapper for
pdfjs
which does not use the unconfigurablefile-loader
.