-
Notifications
You must be signed in to change notification settings - Fork 198
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
digitalbazaar/http-client #516
Comments
As I suggested elsewhere, you might try the solution they recommend: https://jestjs.io/docs/ecmascript-modules. We use our own I think some |
Thank you for your reply. I didn't notice that this http-client is your own package :-) I already tried that experimental flag, but that doesn't solve the problem, as ky-universal does a dynamic import (await import(...)) which leads to a segfault when running code inside the nodejs vm module (Jest uses vm module for isolating test runs from each other). As the node document loader is imported by default, the only solution i've found so far is to patch your package after installation. Once again, thank you for your reply. |
I'm having the same issue, and The best solution would probably be for |
I agree that it would be a good idea to reduce the number of libraries required here (or do some kind of lazy loading) -- provided that it doesn't significantly increase the maintenance burden. That's usually a good practice in general. However, I believe that this extra effort also shouldn't be a pressing matter here or elsewhere in the JavaScript ecosystem; elevating its priority diverts efforts that are being made in other important areas. I certainly sympathize with struggling developers -- but the cause of this perceived need for prioritization should be examined to see if there's a more efficient solution. In my view, the best solution is for any modern tooling that purports to work with JavaScript but does not support features of the ECMAScript standard (such as ESM) should be updated such that they do. It's certainly less efficient for developers to go around either forking and maintaining or requesting modifications to every ESM library they use because it won't run with their tooling -- especially when those libraries follow the ECMAScript standard. It seems to me that whatever tooling (usually TypeScript and / or Jest) is suffering from a lack of ESM support should be updated post-haste -- and the rest of the decentralized ecosystem that is otherwise compliant could be left alone, as it would "just work". |
@dlongley It's not TypeScript or Jest, though, it's Node. ESM support in Node is still experimental. I agree that solving the underlying issue is more effective, but I'm not sure it's reasonable to expect Node itself to move any faster than it already is in that direction. |
And Node community would say it's v8 (and they wouldn't be wrong). My view is that each of those places is a potential bottleneck for addressing the problem. Clearly the most ideal fix is in v8 -- it solves the problem for everyone (once brought into Node, etc.). The next best place for a fix would be Node, and then Jest after that. The worst place (bottleneck-wise) to do the fix would be every ESM library that any developer using Jest depends on (directly or indirectly).
Sure, I'm with you on that. But, given that this problem has now been an issue for at least 2 years, I think the Jest community should move to provide some fix / temporary alternative mode to address the issue. Other testing frameworks (and many applications) are able to work with ESM without issue, including running code in Node. I think that's better than struggling developers going from library to library asking each maintainer to make changes to accommodate Jest (+/- Node +/- v8). Hopefully my position makes sense. Clearly none of this is ideal. |
@dlongley I hear what you're saying. I'm not clear what you think the pragmatic, short term solution is, though? Just…don't just As an entirely separate matter, though, it's frustrating that there's no way to use |
Ah, false alarm, that is the correct way to get to ESM code from CommonJS, I had it in my head it had to be a form of |
Aha! I think I've found the actual issue now. First, you need to run with
Here's what's happening. Notably, this test will reproduce the issue: import { expand } from "jsonld";
test("repro", async () => {
await expand({
abc: "123",
});
}); …while this one won't: import { expand } from "jsonld";
test("repro", async () => {
await expand({
"@context": "http://schema.org/",
abc: "123",
});
}); That's because using a URL context involves the import { expand } from "jsonld";
import { kyPromise } from "@digitalbazaar/http-client";
beforeAll(async () => {
await kyPromise;
});
test("repro", async () => {
await expand({
abc: "123",
});
}); …which is pretty awkward, but does demonstrate that this is the issue. Off the top of my head, I think the best solution here is to make the In any case, if you have an opinion on the strategy here, I'm happy to make a PR to address it. |
Thanks, great analysis! It seems that a PR to http-client could be made that did something to the internals ... like making https://github.com/digitalbazaar/http-client/blob/v3.3.0/lib/httpClient.js#L35-L51 Unfortunately, it seems this would mean that the Any further discussion that relates to http-client specifically should be taken over here: digitalbazaar/http-client#34 |
The deferred dynamic import fix is in |
I'm testing > |
Hello,
I'm having problems to test my code using Jest because jsonld library is using digitalbazaar/http-client, which in turn uses ky-universal/ky, which is only available as ESM build and does a dynamic import.
The underlying V8/node bug is described here: nodejs/node#35889
What's the reason to use digitalbazaar/http-client and not plain fetch (with node-fetch on nodejs)? digitalbazaar/http-client seems to be quite a exotic dependency of your package.
Thank you!
The text was updated successfully, but these errors were encountered: