-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
ReferenceError: AggregateError is not defined #3205
Comments
Unfortunately we can't debug issues that relate to multiple packages outside our control, such as jest-environment-jsdom. Let us know if you come up with reproduction case that just uses jsdom. |
I have no idea how to do that. I'm simply trying to upgrade my testing dependencies to the latest versions and this error is suddenly appearing, with a stack trace that points to this package. Should I file an issue against jest-environment-jsdom? |
Probably! |
@domenic I discovered something very interesting here. I grepped through my node_modules for "AggregateError" and I don't see it referenced in any Jest package. However, I do see it referenced in jsdom:
Here's the entry:
Not knowing what else to try, I deleted this key entirely, and now my tests pass! The weird error and stack trace have disappeared. Are you positive that this package isn't to blame? All fingers are pointing towards jsdom as the culprit here. The stack trace lists jsdom exclusively and a change to jsdom fixes the problem. |
According to MDN, AggregateError only works in Node 15+: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError Is there an implicit assumption that all users of jsdom must be on Node 15+? That would be a shock to me, since 14 is the current LTS version. |
@kaiyoma We check the existence of these classes before trying to use them: jsdom/lib/jsdom/browser/Window.js Line 98 in 0024630
Further, we test all LTS versions back to v10 on our CI system. If jsdom by itself no longer working on v10, we would be the first ones to know about it. The bug could appear when your setup has a combination of following factors:
Item 2 is crucial here. One way to figure out what library conflicts with jsdom is trying to print the value of |
Honestly, this library could be to blame! We just have no way of knowing without you providing us with a minimal reproducible example that does not involve other libraries. We don't have the time to debug all the interactions with various things people layer on top of jsdom so it's just not something we're interested in. |
It's definitely not item 1, as I'm running Node 14.15.5. Item 2 sounds plausible, though I might need help diagnosing that one. As you suggested, I added some logging (
Here's the output of |
I spent the day digging into this, and the good news is that I finally figured out what was happening, and it was indeed a polyfill issue. Context: our Jest config is written in TypeScript, which we load on the fly via a helper script that runs the config through Babel to get ES5/6, which Jest can understand. That helper script loads a few polyfills to do its job, including Lucky for us, our Jest config is comprised entirely of JS primitives, so I can convert it to JSON and avoid this whole transpiling mess entirely. Sorry for the noise, and thank you for the debugging pointers. Your intuition was spot on! And maybe this paper trail will help someone else in the future if they run into a similar issue. |
I think we can be a bit more robust in this scenario regardless. |
If we are running on a JavaScript engine that does not natively support a global in lib/jsdom/browser/js-globals.json, but the user loaded a polyfill prior to loading jsdom, then we could be tricked into assuming that global is available in new VM contexts. Do not assume such a thing, and always check for each global's availability in the VM context. One could test this by running the following script on Node.js v14.x, which does not implement AggregateError natively: global.AggregateError = class AggregateError extends Error {}; const { JSDOM } = require("jsdom"); new JSDOM("", { runScripts: "dangerously" }); Fixes #3205.
Any plan to fix this anytime soon? |
In my case with node@v14.17.4 this problem reproduced with
The reason of this bug is:
To reproduce, make sure youre version of node doesn't have native AggregateError support. |
My temporary solution for this issue is to add this in const vm = require('vm');
const { createContext } = vm;
/**
* Temporary solution for issue [jsdom / ReferenceError: AggregateError is not defined]{@link https://github.com/jsdom/jsdom/issues/3205}
*/
function new_createContext(context) {
if (context && !context.AggregateError && typeof AggregateError === 'function') {
context.AggregateError = AggregateError;
}
return createContext(context);
}
vm.createContext = new_createContext; |
Couldn't get this to work for me unfortunately |
Basic info:
Minimal reproduction case
I recently upgraded jest-environment-jsdom from 26.6.2 to 27.0.3 and I'm now seeing some issues that I believe are related to this package. If I run multiple test files at once, everything is fine, but if I run a single test file, then there's a crash in this package:
I'm not sure what's going wrong here. I've never seen this error before and I can't find any trace of it on the Internet, but after upgrading, everyone on my team is seeing this problem.
I had initially filed this issue here (simon360/jest-environment-jsdom-global#47), but even after purging jest-environment-jsdom-global from the repo, I'm still hitting this crash.
The text was updated successfully, but these errors were encountered: