NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
https://docs.taro.zone/
Other
35.45k stars 4.78k forks source link

Android6及以下版本 Object.assign is not a function #8301

Closed guoseven closed 3 years ago

guoseven commented 3 years ago

相关平台

H5

浏览器版本: Android API23 使用框架: React

复现步骤

run run build:h5

期望结果

页面显示正常

实际结果

白屏

环境信息

  Taro CLI 3.0.14 environment info:
    System:
      OS: macOS 10.15.6
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 14.15.0 - /usr/local/bin/node
      npm: 6.14.8 - /usr/local/bin/npm
    npmPackages:
      @tarojs/components: 3.0.19 => 3.0.19 
      @tarojs/mini-runner: 3.0.19 => 3.0.19 
      @tarojs/react: 3.0.19 => 3.0.19 
      @tarojs/runtime: 3.0.19 => 3.0.19 
      @tarojs/taro: 3.0.19 => 3.0.19 
      @tarojs/webpack-runner: 3.0.19 => 3.0.19 
      babel-preset-taro: 3.0.19 => 3.0.19 
      eslint-config-taro: 3.0.19 => 3.0.19 
      react: ^17.0.1 => 17.0.1 

补充信息

项目构建完成,搭建简单的页面 I/chromium: [INFO:CONSOLE(2)] "Uncaught TypeError: Object.assign is not a function", source:

Chen-jj commented 3 years ago

@guoseven 使用 corejs3。

Taro 的 babel-preset-taro@babel/preset-env 的参数做了一下封装,你需要做的操作是:

  1. babel.config.js 配置 useBuildIns
module.exports = {
  presets: [
    ['taro', {
      framework: 'react',
      ts: false,
      useBuiltIns: 'usage'
    }]
  ]
}
  1. 安装:npm install core-js@3 --savenpm install --save @babel/runtime-corejs3

结果:

image

image

可以自行阅读 Babel 的 preset-envtransform-runtime 文档深究。