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.

Unable to build on latest NodeJS LTS

See original GitHub issue
  • Check if updating to the latest Preact version resolves the issue

Describe the bug At latest NodeJS LTS version, getting following error:

> preact build --no-prerender

 Build  [==                  ] 10% (0.1s) building✖ ERROR 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 (/Users/ajwah/al-mabsut/haidh-guide-app/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/Users/ajwah/al-mabsut/haidh-guide-app/node_modules/webpack/lib/NormalModule.js:417:16)
    at handleParseError (/Users/ajwah/al-mabsut/haidh-guide-app/node_modules/webpack/lib/NormalModule.js:471:10)
    at /Users/ajwah/al-mabsut/haidh-guide-app/node_modules/webpack/lib/NormalModule.js:503:5
    at /Users/ajwah/al-mabsut/haidh-guide-app/node_modules/webpack/lib/NormalModule.js:358:12
    at /Users/ajwah/al-mabsut/haidh-guide-app/node_modules/loader-runner/lib/LoaderRunner.js:373:3
    at iterateNormalLoaders (/Users/ajwah/al-mabsut/haidh-guide-app/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
    at iterateNormalLoaders (/Users/ajwah/al-mabsut/haidh-guide-app/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
    at /Users/ajwah/al-mabsut/haidh-guide-app/node_modules/loader-runner/lib/LoaderRunner.js:236:3
    at context.callback (/Users/ajwah/al-mabsut/haidh-guide-app/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at /Users/ajwah/al-mabsut/haidh-guide-app/node_modules/babel-loader/lib/index.js:59:71

I tried resolving it according to recommendation of webpack, by adding inside preact.config.js:

config.output["hashFunction"] = "xxhash64"

which leads to the next error:

 Build  [==                  ] 10% (0.1s) building✖ ERROR Error: Digest method not supported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (/Users/ajwah/al-mabsut/haidh-guide-app/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/Users/ajwah/al-mabsut/haidh-guide-app/node_modules/webpack/lib/NormalModule.js:417:16)
    at handleParseError (/Users/ajwah/al-mabsut/haidh-guide-app/node_modules/webpack/lib/NormalModule.js:471:10)
    at /Users/ajwah/al-mabsut/haidh-guide-app/node_modules/webpack/lib/NormalModule.js:503:5
    at /Users/ajwah/al-mabsut/haidh-guide-app/node_modules/webpack/lib/NormalModule.js:358:12
    at /Users/ajwah/al-mabsut/haidh-guide-app/node_modules/loader-runner/lib/LoaderRunner.js:373:3
    at iterateNormalLoaders (/Users/ajwah/al-mabsut/haidh-guide-app/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
    at iterateNormalLoaders (/Users/ajwah/al-mabsut/haidh-guide-app/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
    at /Users/ajwah/al-mabsut/haidh-guide-app/node_modules/loader-runner/lib/LoaderRunner.js:236:3
    at context.callback (/Users/ajwah/al-mabsut/haidh-guide-app/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at /Users/ajwah/al-mabsut/haidh-guide-app/node_modules/babel-loader/lib/index.js:59:71

which is on account of the fact that xxhash64 is a webpack specifc implementation.

Considering that preact is based on webpack; I would have expected the above to just work.

To Reproduce

  • In an existing preact project, upgrade to latest NodeJS LTS
  • execute build: preact build --no-prerender

Expected behavior What should have happened when following the steps above?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
Ajwahcommented, Oct 30, 2022

Just wanted to update this issue for future posterity with a more elegant solution. In preact.config.js just add at the top:

const crypto = require("crypto");

/**
 * md4 algorithm is not available anymore in NodeJS 17+ (because of lib SSL 3).
 * In that case, silently replace md4 by md5 algorithm.
 */
try {
  crypto.createHash('md4');
} catch (e) {
  console.warn('Crypto "md4" is not supported anymore by this Node version');
  const origCreateHash = crypto.createHash;
  crypto.createHash = (alg, opts) => {
    return origCreateHash(alg === 'md4' ? 'md5' : alg, opts);
  };
}

Source

1reaction
rschristiancommented, Oct 30, 2022

Ah; I overlooked this. They have the xxhash64 fix only for v5:

I evidently did too! That makes more sense.

So yeah; since you all are diligently busy with the migration to webpack v5

I wouldn’t say that – it’s been started, but isn’t going anywhere fast. Part due to lack of time, part due to Webpack feeling quite like legacy tech, especially now that Sokra and co. have created an actual spiritual successor. It’s hard to justify spending my time at this point (as that PR shows, it’s been only my time) when so many better options exist, albeit with a migration cost attached.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to install latest version of nodejs. I try ... - Stack Overflow
I m trying to install nodejs 17.x but I end up installing nodejs 10.19. | OS : Ubuntu 20.04.4 LTS x86_64 | shell...
Read more >
Building a JavaScript and Node.js project - Travis CI Docs
This guide covers build environment and configuration topics specific to JavaScript and Node.js projects. Please make sure to read our Tutorial and general ......
Read more >
Installing Node.js via package manager
Node.js LTS and npm packages are available in the Main Repository. ... This command in Termux app will install the last available Node.js...
Read more >
Could not install Node.js using .msi (Error 1609) - Super User
Today, I was trying to install the current LTS version of Node.js. But every time I run the installer, I get the same...
Read more >
Can't install the latest version of NodeJs despite update prior ...
Node.js is available from the NodeSource Debian and Ubuntu binary distributions repository ... sudo apt-get install -y build-essential.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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