uniapp对接mqtt,各种报错

如:TypeError: Cannot read property 'language' of undefined,
reportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->Uncaught ReferenceError: process is not defined
打包白屏等问题
1,降低版本 npm i mqtt@3

  1. pc端是ws,移动端是wx
    3.main.js中加,处理报错:TypeError: socketTask.onOpen is not a function
// #ifndef MP
// 处理 wx.connectSocket promisify 兼容问题,强制返回 SocketTask
uni.connectSocket = (function(connectSocket) {
    return function(options) {
        options.success = options.success || function() {}
        return connectSocket.call(this, options)
    }
})(uni.connectSocket)
// #endif

4.mqtt引入路径要变: import * as mqtt from 'mqtt/dist/mqtt';
参考地址:
https://blog.csdn.net/tengyuxin/article/details/132606767
https://blog.csdn.net/song_song0927/article/details/136388233

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容