-
-
Notifications
You must be signed in to change notification settings - Fork 99
ReferenceError: TextEncoder is not defined #209
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
Comments
You need to provide an example that only uses whatwg-url, no other packages, that we can run with |
I am having the same issue |
Is a node version problem: Automattic/mongoose#10713 (comment) |
no, it's not working. |
It is not a node version problem - unless by that you mean my version of nodeJS is too old (which is quite possible)? The comment you linked is a problem of mismatches, from how they phrase it. There is no mismatch between
Update: yeah, Installing Node 12.22.7 fixed it for me. |
Indeed, your version is too old. Node v10 is not supported. |
The same issue on the nodejs v16.13.0 |
@Unrasend it won't happen on v16, you probably have multiple versions of node in your system and something you use to run your code may use different version from what you have when you type i just solved the same issue for someone. IDE was using one version of node (10.x) when running tests, while on the project there was some nvm config that was using 16.x when running tests via |
this stackoverflow helped me https://stackoverflow.com/a/69187990/3642044 |
@dzek69 I've added Had to add the following to jest setup file: import { TextEncoder, TextDecoder } from 'util';
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder; |
@FINDarkside 's solution solved it for me. |
@FINDarkside what's your error message then? Maybe you run something before that mess up the global object? The simplest: console.log(process.version);
console.log(new TextEncoder()); run on node 16.13.2 gives:
Which is expected, docs for that specific version says it's in the global: |
console.log(process.version);
console.log(typeof TextEncoder); logs
This seems to be some kind of issue with jest, jsdom, next.js default test setup or something else, but I won't look into it more since the snippet above solved the issue for me. |
Seems like this issue appears on older versions of node. Updating node to 16.x solved the problem for me. |
This happened to me when I used jest for testing and I got |
* chore: use resolution to resolve cross-fetch to 3.1.5 * chore: use jsdom-custom.js to re-add TextEncoder and TextDecoder Reference: - jsdom/whatwg-url#209
Installing Node 18 fixed it for me. curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash - |
This is the way, thanks a lot. @wyatt8740: sudo apt update -y && sudo apt upgrade -y curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt install nodejs node -v |
@dzek69 really helped me now. I have nvm installed and I didn't know that it existed an node v10 installed without nvm. |
To make it work in node 10: Add this to
You may need to use |
import { TextEncoder, TextDecoder } from 'util';
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder; |
Jest in Next.js(node v20.11.0): // jest.config.ts
import { TextEncoder, TextDecoder } from 'util'
const config: Config = {
globals: {
TextEncoder,
TextDecoder
},
}
export default createJestConfig(config) |
Relative from: Automattic/mongoose#10713
In https://github.com/jsdom/whatwg-url/blob/master/src/encoding.js line 2 says:
But node show an error message:
My node version:
The version in package.json of dependency is:
I installed from
mongoose
package but have last version ofwhatwg-url
package.The text was updated successfully, but these errors were encountered: