[英]ReferenceError: TextEncoder is not defined after update Axios@1.3.1
I had been using Axios v1.2.2 in my project without issues and I decided to update Axios to v1.3.1, after that my app continues running as before, however, all my tests started to fails... ALL OF THEM!!我一直在我的项目中使用 Axios v1.2.2 没有问题,我决定将 Axios 更新到 v1.3.1,之后我的应用程序继续像以前一样运行,但是,我所有的测试开始失败......所有的测试!
Some package versions that I'm using:我正在使用的一些 package 版本:
"axios": "^1.3.1",
"@jest/globals": "^29.4.1",
"@types/jest": "^29.4.0",
"@testing-library/dom": "^8.20.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.4.3",
This is the error that I'm getting in all my tests:这是我在所有测试中遇到的错误:
Test suite failed to run
ReferenceError: TextEncoder is not defined
> 1 | import { AxiosError } from "axios";
| ^
2 |
3 | class UnknownResponseFormat<T = unknown, D = unknown> extends AxiosError<T, D> {
4 | static readonly ERR_UNKNOWN_RESPONSE_FORMAT = "ERR_UNKNOWN_RESPONSE_FORMAT";
I also found some workarounds for this on the inte.net, some things like this...我还在 inte.net 上找到了一些解决方法,比如这样的东西......
if (typeof global.TextEncoder === "undefined") {
const { TextEncoder, TextDecoder } = require("util");
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
}
...but it doesn't work either. ...但它也不起作用。
PLEASE!请! SOMEBODY HELP ME!
来人帮帮我!
I've encountered same problem.我遇到过同样的问题。 I think problem appered from version 1.3.0, I've checked version 1.2.6 and it's ok.
我认为问题是从 1.3.0 版本开始出现的,我检查了 1.2.6 版本,没问题。
I didn't see any breaking changes in release notes , so I created support/question issue on github project .我没有在发行说明中看到任何重大更改,因此我在 github 项目上创建了支持/问题问题。
I hope I will find solution or they will answer me.我希望我能找到解决方案,否则他们会回答我。
If you need quick workaround, just change axios version to 1.2.6 in your package.json file .如果您需要快速解决方法,只需将 package.json 文件中的 axios 版本更改为 1.2.6 。 If any your dependencies are fetching axios in >= 1.3.0 use override option, ex.:
如果您的任何依赖项在 >= 1.3.0 中获取 axios,请使用覆盖选项,例如:
...
"overrides": {
"your-dependecy-package": {
"axios": "1.2.6"
}
},
...
For me I had to add the following lines before running axios to resolve a similar issue (have never used axios before):对我来说,我必须在运行 axios 之前添加以下行来解决类似的问题(以前从未使用过 axios):
import { TextEncoder, TextDecoder } from 'text-encoding'; global.TextEncoder = TextEncoder; global.TextDecoder = TextDecoder;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.