Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

编译报错,使用core-js,解决mbox问题,遇到 头条字节的global对象和微信的global对象属性差异较大,无法使用var NativeArrayBuffer = globalThis[ARRAY_BUFFER]; #17317

Closed
CatkinLi opened this issue Feb 14, 2025 · 1 comment

Comments

@CatkinLi
Copy link

Image
Image

相关平台

字节跳动小程序

小程序基础库: 3.52.0.14
使用框架: React

复现步骤

import { useLaunch, usePageNotFound } from '@tarojs/taro';
import React from 'react';
import { Provider } from 'mobx-react';
import './app.scss';
import 'core-js/stable';
import userStore from "@common/store/user";
import VConsole from 'vconsole';

let uma = {};

if (typeof PRERENDER === 'undefined') {
if (process.env.TARO_ENV === 'weapp') {
uma = require('umtrack-wx');
uma.init({
appKey: 'XXXX',
useOpenid: true,
autoGetOpenid: true,
debug: false
});
}
}

//把uma 添加到Taro,后续通过Taro.uma调用uma方法 ,es6模块导入的是模块引用,
//因此放心注入,后面页面导入Taro模块是可以获取uma的
import Taro from '@tarojs/taro';
Taro.uma = uma;
//调用事件
// Taro.uma.trackEvent('bu7y', {
// name: 'car'
// });

function App({ children }) {
const store = { user: userStore };
useLaunch((option) => {
if (process.env.TARO_ENV === "h5" && option.query.vconsole) {
const vConsole = new VConsole();
}
if (!Taro.getStorageSync("src")) {
let src = process.env.TARO_ENV === "h5" ? "wap" : "yyxcxliebian";
Taro.setStorageSync("src", src);
}
if (process.env.TARO_ENV !== "h5") {
const updateManager = Taro.getUpdateManager()
if (updateManager.onCheckForUpdate) {
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
// console.log(res.hasUpdate)
})
updateManager.onUpdateReady(function () {
Taro.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
}
}
})

usePageNotFound((res) => {
Taro.switchTab({
url: '/pages/expo/index'
})
})

// children 是将要会渲染的页面
return (
<Provider {...store}>{children}
)
}

export default App

期望结果

var globalThis = webpack_require(/*! ../internals/global-this */ "./node_modules/core-js/internals/global-this.js");
期望 globalThis 对象内容和微信小程序保持一致

实际结果

var globalThis = webpack_require(/*! ../internals/global-this */ "./node_modules/core-js/internals/global-this.js");
globalThis对象缺少很多字段

环境信息

👽 Taro v3.6.20


  Taro CLI 3.6.20 environment info:
    System:
      OS: Windows 11 10.0.22631
    Binaries:
      Node: 18.18.2 - C:\opensource\nodejs\node.EXE
      npm: 9.8.1 - C:\opensource\nodejs\npm.CMD
    npmPackages:
      @tarojs/cli: 3.6.30 => 3.6.30
      @tarojs/components: 3.6.30 => 3.6.30
      @tarojs/helper: 3.6.30 => 3.6.30
      @tarojs/plugin-framework-react: 3.6.30 => 3.6.30
      @tarojs/plugin-html: 3.6.30 => 3.6.30
      @tarojs/plugin-platform-alipay: 3.6.30 => 3.6.30
      @tarojs/plugin-platform-h5: 3.6.30 => 3.6.30
      @tarojs/plugin-platform-jd: 3.6.30 => 3.6.30
      @tarojs/plugin-platform-qq: 3.6.30 => 3.6.30
      @tarojs/plugin-platform-swan: 3.6.30 => 3.6.30
      @tarojs/plugin-platform-tt: 3.6.30 => 3.6.30
      @tarojs/plugin-platform-weapp: 3.6.30 => 3.6.30
      @tarojs/react: 3.6.30 => 3.6.30
      @tarojs/runtime: 3.6.30 => 3.6.30
      @tarojs/shared: 3.6.30 => 3.6.30
      @tarojs/taro: 3.6.30 => 3.6.30
      @tarojs/taro-loader: 3.6.30 => 3.6.30
      @tarojs/webpack5-runner: 3.6.30 => 3.6.30
      @tarojs/with-weapp: 3.6.30 => 3.6.30
      babel-preset-taro: 3.6.30 => 3.6.30
      eslint-config-taro: 3.6.30 => 3.6.30
      react: ^18.0.0 => 18.2.0
@CatkinLi CatkinLi changed the title 编译报错,使用core-js,解决mbox问题,遇到 字节的global对象和微信的global对象属性差异较大 编译报错,使用core-js,解决mbox问题,遇到 头条字节的global对象和微信的global对象属性差异较大,无法使用var NativeArrayBuffer = globalThis[ARRAY_BUFFER]; Feb 14, 2025
This was referenced Feb 15, 2025
@CatkinLi
Copy link
Author

这个问题不用看了,被deepseek误导了,其实是MBox的使用问题,有同样问题的同学可以参考https://github.com/NervJS/taro/issues/12979, 解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant