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

taro升级3.5.0 使用webpack4初始化的模板报错:TypeError: Cannot read properties of undefined (reading 'mount') #12134

Closed
WhiteSean opened this issue Jul 27, 2022 · 3 comments
Assignees
Labels
F-react Framework - React T-alipay Target - 编译到支付宝小程序 V-3 Version - 3.x walk-around 绕过问题

Comments

@WhiteSean
Copy link
Contributor

相关平台

支付宝小程序

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

复现步骤

使用3.5.0 使用webpack4 选择默认模板即可重现

期望结果

正常

实际结果

报错

环境信息

Taro CLI 3.5.0 environment info:
    System:
      OS: macOS 10.15.6
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 16.14.2 - /usr/local/bin/node
      Yarn: 1.22.10 - /usr/local/bin/yarn
      npm: 8.5.0 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: 3.5.0 => 3.5.0 
      @tarojs/components: 3.5.0 => 3.5.0 
      @tarojs/helper: 3.5.0 => 3.5.0 
      @tarojs/mini-runner: 3.5.0 => 3.5.0 
      @tarojs/plugin-framework-react: 3.5.0 => 3.5.0 
      @tarojs/plugin-platform-alipay: 3.5.0 => 3.5.0 
      @tarojs/plugin-platform-jd: 3.5.0 => 3.5.0 
      @tarojs/plugin-platform-qq: 3.5.0 => 3.5.0 
      @tarojs/plugin-platform-swan: 3.5.0 => 3.5.0 
      @tarojs/plugin-platform-tt: 3.5.0 => 3.5.0 
      @tarojs/plugin-platform-weapp: 3.5.0 => 3.5.0 
      @tarojs/react: 3.5.0 => 3.5.0 
      @tarojs/router: 3.5.0 => 3.5.0 
      @tarojs/runtime: 3.5.0 => 3.5.0 
      @tarojs/shared: 3.5.0 => 3.5.0 
      @tarojs/taro: 3.5.0 => 3.5.0 
      @tarojs/taro-h5: 3.5.0 => 3.5.0 
      @tarojs/webpack-runner: 3.5.0 => 3.5.0 
      babel-preset-taro: 3.5.0 => 3.5.0 
      eslint-config-taro: 3.5.0 => 3.5.0 
      react: ^18.0.0 => 18.2.0 
    npmGlobalPackages:
      typescript: 4.7.4
@taro-bot2 taro-bot2 bot added F-react Framework - React T-alipay Target - 编译到支付宝小程序 V-3 Version - 3.x labels Jul 27, 2022
@Chen-jj Chen-jj self-assigned this Jul 28, 2022
@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 28, 2022

这里存在两个问题:

一、React 18 createRoot 异步渲染导致与小程序 onLaunch onLoad 的竞态问题,#12145 已修复

但应用上述修复后还会出现第二个问题:白屏、无报错。

原因是 createRoot 使用了 setImmediate API,Webpack4 会使用 YuzuJS/setImmediate 包注入 setImmediate API。

YuzuJS/setImmediate 是非常古老的一个包,关键在于它的 setTimeout 语法是这样写的:

https://github.com/YuzuJS/setImmediate/blob/f1ccbfdf09cb93aadf77c4aa749ea554503b9234/setImmediate.js#L154

它为 setTimeout 传递了第三个参数,符合 Web 规范支付宝小程序的 setTimeout 不支持传递第三个参数,所以导致 React18 挂载失败从而白屏。

或许我们可以写一个 webpack-loader 去处理 YuzuJS/setImmediate 的 setTimeout 写法,但目前建议开发者先自行绕过:

使用 Webpack4 开发支付宝小程序时,请使用 React17。

@Solyna
Copy link

Solyna commented Jun 28, 2023

使用3.6.8,微信,真机调试和预览就会报错:
image

@50431040
Copy link

50431040 commented Sep 7, 2023

taro版本3.5.12,微信小程序,线上也出现了这个问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-alipay Target - 编译到支付宝小程序 V-3 Version - 3.x walk-around 绕过问题
Projects
None yet
Development

No branches or pull requests

4 participants