从截图看,这是 wasm 胶水代码里用到了 TextDecoder。Native 运行时基于 V8,不是浏览器环境,没有内置 TextDecoder/TextEncoder 这些 Web API。
在加载 wasm 模块之前,手动加一个 polyfill 就行:
if (typeof TextDecoder === 'undefined') {
globalThis.TextDecoder = function(enc) { this._enc = enc || 'utf-8'; };
TextDecoder.prototype.decode = function(buf) {
if (!buf) return '';
var u = buf instanceof Uint8Array ? buf : new Uint8Array(buf instanceof ArrayBuffer ? buf : buf.buffer || buf);
var s = '', i = 0;
while (i < u.length) {
var c = u[i++];
if (c < 0x80) { s += String.fromCharCode(c); }
else if (c < 0xE0) { s += String.fromCharCode(((c & 0x1F) << 6) | (u[i++] & 0x3F)); }
else if (c < 0xF0) { s += String.fromCharCode(((c & 0x0F) << 12) | ((u[i++] & 0x3F) << 6) | (u[i++] & 0x3F)); }
else { var cp = ((c & 0x07) << 18) | ((u[i++] & 0x3F) << 12) | ((u[i++] & 0x3F) << 6) | (u[i++] & 0x3F); cp -= 0x10000; s += String.fromCharCode(0xD800 + (cp >> 10), 0xDC00 + (cp & 0x3FF)); }
}
return s;
};
}
if (typeof TextEncoder === 'undefined') {
globalThis.TextEncoder = function() {};
TextEncoder.prototype.encode = function(str) {
var arr = [];
for (var i = 0; i < str.length; i++) {
var c = str.charCodeAt(i);
if (c < 0x80) arr.push(c);
else if (c < 0x800) { arr.push(0xC0 | (c >> 6), 0x80 | (c & 0x3F)); }
else { arr.push(0xE0 | (c >> 12), 0x80 | ((c >> 6) & 0x3F), 0x80 | (c & 0x3F)); }
}
return new Uint8Array(arr);
};
}
把这段代码放到项目入口最前面(比如 index.js 开头),确保在 wasm 加载之前执行即可。
以上由 AI 自动回复,仅供参考。若无异议将不再人工审查;如需人工介入请回帖说明。