I am using Jest to run my tests. After an upgrade to Node v16.13.0 (the LTS version) from v12, I got the following error:
ReferenceError: AbortController is not defined
Whereas running the code manually with Node worked fine.
I upgraded all my packages to the newest versions during the upgrade to v16. I had been using a polyfill for a mock AbortController because I was using Node v12 before the upgrade. Node v16 comes with its own AbortController, so I removed the polyfill. I am using TypeScript 4.4.4, in case that's relevant (this is not a TypeScript error).
This error did not occur with the polyfill.
It seems that when Jest runs it is not using the same environment compared to when I manually run my app with Node.
I tried the following:
- Make Node v16.13.0 the default version using nvm
- Remove all other versions of Node installed except v16.13.0
- Run
console.log(process.env)at the start of the test and check what Node version is being used -> All references to Node had that same version: 16.13.0.
I've been at this for hours and it seems nobody on the internet has had this problem. Does anyone have any idea what is going on?