微信小游戏报错:TypeError: Function(...) is not a function

我的小游戏使用了protobuf.js,其中一段协议处理代码在pc浏览器中运行时是正常的,但到在微信开发者工具中就报了上面的错误,具体代码如下:

protected _createMessage( root, messageName, data ) {

let proto = root.lookupType(messageName);

let errMsg = proto.verify(data); // 这里是报错行

if (errMsg)

throw Error(err:${errMsg.toString()}, msg:${messageName});

let message = proto.create(data);

let buffer = proto.encode(message).finish();

return buffer;

}

报错堆栈:

img_v2_97b1742b-d9ce-43d0-af24-90bae3e312dg

报错的方法位置:

有没有碰到过类似问题的小伙伴提供些解决思路?

1赞


帮你用chatgpt问了下 :joy:

微信小游戏不支持动态执行 JS 代码,建议转为单个 proto.js 文件来使用

谢谢,标记一下可以用