Requirements: The endUniApp
of has been in normal use, and now it is going to be compatible .H5
微信小程序
1. Problem analysis
I thought it should be smooth, but I reported an error as soon as I came up, and I was very flustered. The error message is as follows:
页面[components/major/major-intro]错误:
TypeError: Cannot read property 'FormData' of undefined
at Object.<anonymous> (vendor.js?t=wechat&s=1679123222779&v=0a98776a18c77e11bdf2a8a15af44f38:20109)
at __webpack_require__ (runtime.js?t=wechat&s=1679123222779&v=c88fbffc60b4101fd05b6808eff1ad49:92)
at Object.<anonymous> (vendor.js?t=wechat&s=1679123222779&v=0a98776a18c77e11bdf2a8a15af44f38:20097)
at __webpack_require__ (runtime.js?t=wechat&s=1679123222779&v=c88fbffc60b4101fd05b6808eff1ad49:92)
at Object.<anonymous> (vendor.js?t=wechat&s=1679123222779&v=0a98776a18c77e11bdf2a8a15af44f38:19751)
at Object.<anonymous> (vendor.js?t=wechat&s=1679123222779&v=0a98776a18c77e11bdf2a8a15af44f38:19976)
at __webpack_require__ (runtime.js?t=wechat&s=1679123222779&v=c88fbffc60b4101fd05b6808eff1ad49:92)
at Object.<anonymous> (vendor.js?t=wechat&s=1679123222779&v=0a98776a18c77e11bdf2a8a15af44f38:19681)
at __webpack_require__ (runtime.js?t=wechat&s=1679123222779&v=c88fbffc60b4101fd05b6808eff1ad49:92)
at Object.<anonymous> (vendor.js?t=wechat&s=1679123222779&v=0a98776a18c77e11bdf2a8a15af44f38:19609)
(env: Windows,mp,1.06.2209190; lib: 2.30.2)
Click on the source code to see this:
/***/ }),
/* 170 */
/*!***********************************************!*\
!*** ./node_modules/form-data/lib/browser.js ***!
\***********************************************/
/*! no static exports found */
/***/ (function(module, exports) {
/* eslint-env browser */
module.exports = typeof self == 'object' ? self.FormData : window.FormData;
/***/ }),
[Note] At the beginning, I thought it was 微信小程序
a compatibility or uniapp
compatibility problem, but I went to search inaxios
, and found that someone had the same problem. GitHub
issue
Ah,,,,, it seems that these three have their own problems.
Issue
Address: node Cannot read property 'FormData' of undefined #5201
After many times of tossing and verification, I don’t recognize anyone who cares, and I have a high probability of solving the case: it is on the WeChat applet, which leads to a problem axios
in the judgment, and there is no such error in the H5 browser (it seems that these two The pot, it’s really not uniapp
my pot, haha).
2. Solutions
2.1 Reduce the version of axios
axios
0.x
The highest version of is 0.27.2
version, so just do the following.
# 移除已有的 axios
npm uninstall axios
# 安装指定版本的 axios
npm install [email protected]
2.2 Improve to the specified version of axios (recommended)
1.2.1
The version is used in the project ( it will report an error ). As of March 18, 2023 , the latest version is 1.3.4
, so 1.3.4
the version . The result is usable and no error is reported.
From this, it can be concluded that it is estimated that there is also a problem axios
with itself , but it is not known which version is repaired, and there is no in-depth investigation.
# 移除已有的 axios
npm uninstall axios
# 安装指定版本的 axios
npm install [email protected]
[Note] Guys, if other versions can also be used, please let me know! I wish you a lot of hair! ! !
Personal blog: Roc's Blog