whatsapp-web.js,如何修复 TypeError:无法读取 null 的属性(读取“1”)

问题描述 投票:0回答:2

const 版本=indexHtml.match(/manifest-([\d.]+).json/)[1]; ^

TypeError:无法读取 null 的属性(读取“1”) 在 LocalWebCache.persist (/Users/abc/Desktop/haba/node_modules/whatsapp-web.js/src/webCache/LocalWebCache.js:29:69) 在/Users/abc/Desktop/haba/node_modules/whatsapp-web.js/src/Client.js:744:36 在 process.processTicksAndRejections (节点:内部/进程/task_queues:95:5)

Node.js v20.11.1

第二次运行代码,总是出现这个错误。

我正在使用nodemon,所以我这样做了:npx nodemon index.js 运行流畅

javascript node.js whatsapp
2个回答
3
投票

将您的客户端代码更改为:

const 客户端 = 新客户端({ authStrategy: 新的 LocalAuth({ 数据路径:“会话”, }), 网络版本缓存:{ 类型:'远程', RemotePath: 'https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2412.54.html', } });


0
投票

编辑LocalWebCache.js持久化函数

async persist(indexHtml) {
    // extract version from index (e.g. manifest-2.2206.9.json -> 2.2206.9)
    if(indexHtml.match(/manifest-([\d\\.]+)\.json/)!=null){
        const version = indexHtml.match(/manifest-([\d\\.]+)\.json/)[1];
        if(!version) return;

        const filePath = path.join(this.path, `${version}.html`);
        fs.mkdirSync(this.path, { recursive: true });
        fs.writeFileSync(filePath, indexHtml);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.