-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
panic when using jest, jsdom and TextEncoder #2532
Comments
It's trivial to break esbuild by running it in a broken JavaScript environment. This is not surprising, and does not indicate a problem with esbuild. You can get a similar error by running this code in node without Jest, for example: global.TextEncoder = class { encode = x => x }
const esbuild = require('esbuild')
esbuild.transform('1+2').then(x => console.log(x)) The support code for esbuild relies on a sane and functioning Edit: Or maybe you have written the bug yourself in |
Closing as out of scope. In a future breaking change, I could have esbuild do a sanity check for this edge case and throw an error earlier if this API is broken. |
Thank you for taking the time, this helped me narrow down the issue further jestjs/jest#13227 |
FWIW something like this seems to work: const util = require("util");
if (!global.TextDecoder) {
global.TextDecoder = util.TextDecoder;
}
if (!global.TextEncoder) {
global.TextEncoder = class extends util.TextEncoder {
encode(text) {
return new Uint8Array(super.encode(text));
}
};
} In case you're still working on this. |
Yes, thank you. I considered it, but ultimately the test that triggered this issue shouldn't have been using the jsdom environment at all. I just made sure it uses the correct environment and that solves it as well. |
Minimal reproduction repo: https://github.com/Janpot/jest-esbuild-repro
Running
esbuild
in jest with this particularTextEncoder
,textDecoder
polyfill setup started breaking from[email protected]
onward.To reproduce, clone the repo, run
yarn && yarn test
. It will error withThe README contains a few of the tweaks that all make the error go away.
environment: node v16.17.0 on MacOs
The text was updated successfully, but these errors were encountered: