TypeError Cannot read property wx of undefined in uni-app

TypeError Cannot read property wx of undefined in uni-app

示例代码:

新空白项目VUE2

操作步骤:

新空白项目VUE2 运行到小程序

预期结果:

正常

实际结果:

TypeError: Cannot read property 'wx' of undefined

bug描述:

新建空白项目 只要是 VUE2 版本就会出现 TypeError: Cannot read property 'wx' of undefined  

app.js错误:
TypeError: Cannot read property 'wx' of undefined
at Object.<anonymous> (wx.js?3223:23)
at webpack_require (null:81)
at Object.0 (main.js:28)
at webpack_require (null:81)
at checkDeferredModules (null:47)
at Array.webpackJsonpCallback [as push] (null:34)
at main.js:2
at VM163 WASubContext.js:1
at f.runWith (VM163 WASubContext.js:1)
at q (VM163 WASubContext.js:1)(env: macOS,mp,1.06.2504050; lib: 3.10.3)

TypeError: Cannot read property 'wx' of undefined
at Object.<anonymous> (wx.js?3223:23)
at webpack_require (null:81)
at Object.0 (main.js:28)
at webpack_require (null:81)
at checkDeferredModules (null:47)
at Array.webpackJsonpCallback [as push] (null:34)
at main.js:2
at VM163 WASubContext.js:1
at f.runWith (VM163 WASubContext.js:1)
at q (VM163 WASubContext.js:1)(env: macOS,mp,1.06.2504050; lib: 3.10.3)

TypeError: Cannot read property 'wx' of undefined
at Object.<anonymous> (wx.js?3223:23)
at webpack_require (null:81)
at Object.0 (main.js:28)
at webpack_require (null:81)
at checkDeferredModules (null:47)
at Array.webpackJsonpCallback [as push] (null:34)
at main.js:2
at VM163 WASubContext.js:1
at f.runWith (VM163 WASubContext.js:1)
at q (VM163 WASubContext.js:1)(env: macOS,mp,1.06.2504050; lib: 3.10.3)
开发环境 版本号 项目创建方式
Mac 15.0 HBuilderX
4.84
最新版本
3.10.3

更多关于TypeError Cannot read property wx of undefined in uni-app的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

mac删除一下
~/Library/Application Support/微信开发者工具(或微信web开发者工具) ~/Library/Caches/微信开发者工具(或微信web开发者工具
然后回退到这个版本就好了
https://developers.weixin.qq.com/community/minihome/doc/000ac62bb84690fb7553e3d4061801?blockType=99

更多关于TypeError Cannot read property wx of undefined in uni-app的实战教程也可以访问 https://www.itying.com/category-93-b0.html


1、微信开发者工具更改基础库试试 2、删掉unpackage----dist----dev----mp-weixin文件重新编译试试 3、微信开发者工具升级或降低版本 4、hbuilderx降低或者升级版本

这是一个已知的uni-app兼容性问题,通常出现在Vue2项目运行到小程序时。问题根源在于uni-app框架内部对微信小程序API的调用时机。

解决方案:

  1. 升级HBuilderX到最新版本,确保使用的是最新的uni-app框架。老版本可能存在此兼容性问题。

  2. 检查manifest.json配置,确认小程序配置正确,特别是AppID等基础配置。

  3. 清理项目并重新运行

    • 删除unpackagenode_modules文件夹
    • 运行npm install重新安装依赖
    • 重新编译到小程序
  4. 如果问题依旧,在main.js中添加以下代码:

// 确保在创建Vue实例前执行
if (typeof wx !== 'undefined') {
  uni = wx
}
回到顶部