-
Notifications
You must be signed in to change notification settings - Fork 13
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
Bumping to 0.16.0 - ReferenceError: TextEncoder is not defined #91
Comments
Hi @danpottshimself , Thanks for reporting the issue. First of all, let's make sure that you don't have any dependency conflicts by removing npm install
# or
yarn |
By the way, I reformatted the issue description a little bit. |
I've just added an additional automated test to cover your particular case and it passed. |
@kkomelin odd, I guess this could be some form of clash between dependencies I have installed elsewhere. I have tried multiple node module cleans/rm's and re-installs to no avail. I guess the issue is my side so you can close this issue, thanks for the support |
I'm also getting this fwiw, so it is slightly broader. Not entirely sure what the conflict is, perhaps one of the dependencies here isn't tightly bound enough so something else is pinning it to an older version? |
That makes me feel less crazy @cnorthwood. I was originally thinking it could be jsdom environment potentially since in version 16, it looks like jest etc have been bumped? |
ah yes - that would explain it, and why @kkomelin's automated test passed. Jest with JSDom polyfills that call by itself, so it'll work in a Jest environment because JSDom has polyfilled that function, but won't when not running under Jest. |
Thanks guys. I will try to reproduce the issue without Jest. Will keep you updated. |
Just tested through a console Node.js script (Node 14.16): require('isomorphic-dompurify');
DOMPurify.setConfig({ALLOWED_TAGS: ['b']});
console.log(DOMPurify.sanitize('<b>dddd</b><iframe>Iframe!</iframe>')); And it worked fine. Could you please give me more details on what are your environments so I could try to reproduce the issue locally? Server/client? Next.js/React/others? |
By the way, do you use Yarn or NPM for dependency management? |
I use Yarn - I've rolled back for now but will try and reproduce. This is server-side Node 14 (Apollo Server) with TypeScript. I dont' use DOMPurify as a global like that, this is how I use it:
|
Thanks @cnorthwood Will try to play with your example. Although I don't think it helps but I've just updated |
sadly not. For more info, here's the full stack trace I get:
|
so the issue appears to be in whatwg-url
|
Just for reference jsdom/whatwg-url#209 |
Ah, so it's a version mismatch with Jest and that breaking it: https://stackoverflow.com/questions/57712235/referenceerror-textencoder-is-not-defined-when-running-react-scripts-test |
Good catch @cnorthwood ! Now when we know the cause, what solution would you recommend? |
Jsdom is a complex project which has already caused some dependency pain #54 |
For anyone hitting this same issue, I was able to fix this on a project (which had a failing test due to this error) by including the following in my
|
I installed and I'm facing a similar issue. Everything seems fine.
I tried to print the process version using What is the right solution? Node version: |
I've tried
in my jest setup but I just get this error:
any ideas? edit: for anybody having this issue, I fixed it by importing from 'node:util'
|
I've tried each one of the solutions provided above but since i'm working with nextJest the tests were failing.
to the personalized configuration for jest, in this file i just imported TextEncoder and TextDecoder from util:
|
For me, I had to add the following to
and import the lib like |
For me, the TextDecoder had a type mismatch issue with the above approach, so I solved it with this syntax instead:
Thanks to leonheess - https://stackoverflow.com/questions/68468203/why-am-i-getting-textencoder-is-not-defined-in-jest |
Not reproducible for me anymore in |
@kopach Thanks for the update. Yes, it's a very old issue, so let's close it for now. |
When installing -
"isomorphic-dompurify": "^0.16.0"
I get the following error within a jest test that previously passed.js file:
Test:
Any ideas what this may be? Thanks in advance
The text was updated successfully, but these errors were encountered: