Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build on latest NodeJS LTS #1748

Closed
1 task done
Ajwah opened this issue Oct 29, 2022 · 8 comments
Closed
1 task done

Unable to build on latest NodeJS LTS #1748

Ajwah opened this issue Oct 29, 2022 · 8 comments

Comments

@Ajwah
Copy link

Ajwah commented Oct 29, 2022

  • 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?

@rschristian rschristian transferred this issue from preactjs/preact Oct 30, 2022
@rschristian
Copy link
Member

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

preact-cli is indeed Webpack-based, but actually, this is an issue with Webpack itself. See webpack/webpack#14532

Not sure about that xxhash64 recommendation, but setting your SSL provider to the legacy version did work in the past:

NODE_OPTIONS=--openssl-legacy-provider preact build ...

Can you try setting this env var instead?

@Ajwah
Copy link
Author

Ajwah commented Oct 30, 2022

but setting your SSL provider to the legacy version did work in the past:

NODE_OPTIONS=--openssl-legacy-provider preact build ...

Can you try setting this env var instead?

It nullifies the effort the node team has done in NodeJS 18. I have currently adopted this as a hack as a temporary measurement to keep my project going. Longer-term; we should be all using the default openssl provider.

@Ajwah
Copy link
Author

Ajwah commented Oct 30, 2022

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

preact-cli is indeed Webpack-based, but actually, this is an issue with Webpack itself. See webpack/webpack#14532

Not sure about that xxhash64 recommendation

Correct; it was an issue with webpack itself; but then they put in the xxhash64-fix. It is the recommendation. If you look at the issue you linked; a bit down is where they state:

We are planning to migrate to a different hash function anyway for webpack 6. So currently you will have to use output.hashFunction: "xxhash64" in configuration to fix that

That is why I was motivating: config.output["hashFunction"] = "xxhash64" inside preact.config.js to work out of the box.

@rschristian
Copy link
Member

It nullifies the effort the node team has done in NodeJS 18.

No, what it does is fix an issue that broke a huge portion of the Node ecosystem.

The Node team of course recognized this and added an option that's meant to be used for exactly this purpose. It doesn't nullify their work at all, nor is the work done to migrate particularly compelling. You'll see 0 difference in normal use cases.

Longer-term; we should be all using the default openssl provider.

Did you read the linked issue? It's a Webpack issue, and they have no interest in back-porting the fix, unfortunately. preact-cli isn't doing anything special here.

Contributions are always welcome if you'd like to help the v4 upgrade where we can move to Webpack v5. See #1647.

Going to close this out as there's nothing actionable (that isn't a duplicate).

@rschristian
Copy link
Member

That is why I was motivating: config.output["hashFunction"] = "xxhash64" inside preact.config.js to work out of the box.

Well, evidently it does not. And in light of the other recommendation provided in that same comment working perfectly, I don't find it particularly compelling to investigate at this time. If you do, and are able to suggest a fix to preact-cli to support that, I'd be happy to incorporate it in.

@Ajwah
Copy link
Author

Ajwah commented Oct 30, 2022

Contributions are always welcome if you'd like to help the v4 upgrade where we can move to Webpack v5.

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

We will not update that in webpack 4.

so for v4 the only solutions are:

  • export NODE_OPTIONS=--openssl-legacy-provider
  • monkey patching crypto for md4 and Node.js v17

So yeah; since you all are diligently busy with the migration to webpack v5; it makes sense to close this issue; it should work out of the box once you have upgraded to v5.

Contributions are always welcome if you'd like to help the v4 upgrade where we can move to Webpack v5.

Thanks for the invitation!

@rschristian
Copy link
Member

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.

@Ajwah
Copy link
Author

Ajwah commented 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants