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 项目中使用 @tarojs/components 报错 #9064

Closed
xughv opened this issue Apr 8, 2021 · 3 comments
Closed

非 Taro 项目中使用 @tarojs/components 报错 #9064

xughv opened this issue Apr 8, 2021 · 3 comments

Comments

@xughv
Copy link
Contributor

xughv commented Apr 8, 2021

相关平台

H5

浏览器版本: Chrome 89
使用框架: React

复现步骤

非 Taro 构建项目参照 #6883 配置可运行,但使用到 Swiper 时发生异常。

看了下好像是因为没有环境变量时全局的 getComputedStyle 被覆盖了,新的方法在 H5 下行为不太对:

if (process.env.TARO_ENV !== 'h5') {
(window as any).requestAnimationFrame = raf;
(window as any).cancelAnimationFrame = caf;
(window as any).getComputedStyle = getComputedStyle

表现

没有正确获取到样式:

image


image

期望结果

无环境变量时不覆盖全局方法

实际结果

全局方法被覆盖

环境信息

  Taro CLI 3.0.21 environment info:
    System:
      OS: Linux 4.4 Ubuntu 18.04.2 LTS (Bionic Beaver)
      Shell: 5.4.2 - /usr/bin/zsh
    Binaries:
      Node: 12.13.0 - /usr/local/bin/node
      Yarn: 1.9.2 - /mnt/c/Program Files (x86)/Yarn/bin/yarn
      npm: 6.12.0 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: ^3.0.21 => 3.0.21
      @tarojs/components: ^3.0.21 => 3.0.21
      @tarojs/mini-runner: ^3.0.21 => 3.0.21
      @tarojs/react: ^3.0.21 => 3.0.21
      @tarojs/runtime: ^3.0.21 => 3.0.21
      @tarojs/webpack-runner: ^3.0.21 => 3.0.21
      babel-preset-taro: ^3.0.21 => 3.0.21
      eslint-config-taro: ^3.0.21 => 3.0.21
      postcss-pxtransform: ^3.2.1 => 3.2.1
      react: ^17.0.2 => 17.0.2
@Chen-jj
Copy link
Contributor

Chen-jj commented Apr 8, 2021

设置一下环境变量咯

@xughv
Copy link
Contributor Author

xughv commented Apr 8, 2021

设置一下环境变量咯

自定义构建设置了环境变量会报另一个问题 .. runtime 里面找不到 React,还不清楚原因 ..

image

@xughv
Copy link
Contributor Author

xughv commented Apr 8, 2021

覆盖这里判断下?

if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') { }

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

2 participants