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

babel-preset-taro 设置 useBuiltIns: 'usage' 会导致 @babel/preset-env 和 @babel/plugin-transform-runtime 都设置了core.js: 3.0, 导致编译报错 #9705

Closed
wanqing19954 opened this issue Jul 7, 2021 · 4 comments · Fixed by #9855 or #9858
Labels
F-vue2 Framework - Vue 2 good first issue Good for newcomers T-h5 Target - 编译到 H5 V-3 Version - 3.x
Milestone

Comments

@wanqing19954
Copy link

相关平台

H5

复现仓库

https://github.com/wanqing19954/taro-vue/blob/dev/babel.config.js
浏览器版本: Chrome 62
使用框架: Vue 2

复现步骤

  • 将babel.configjs, useBuiltIn 设置为usage
  • 安装依赖, npm run dev:h5
  • 打开页面,打开浏览器控制台,发现报错 Can't call method on undefined
  • image

期望结果

希望设置 @babel/plugin-transform-runtime, envOptions corejs 选项默认为false, 可以编译成功

实际结果

目前设置useBuiltIn: 'usage' , npm run dev:h5 报错

环境信息

  Taro CLI 3.2.9 environment info:
    System:
      OS: macOS 10.14.6
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 14.15.2 - ~/.nvm/versions/node/v14.15.2/bin/node
      Yarn: 1.22.4 - /usr/local/bin/yarn
      npm: 6.14.9 - ~/.nvm/versions/node/v14.15.2/bin/npm
    npmPackages:
      @tarojs/components: 3.2.15 => 3.2.15 
      @tarojs/mini-runner: 3.2.15 => 3.2.15 
      @tarojs/runtime: 3.2.15 => 3.2.15 
      @tarojs/taro: 3.2.15 => 3.2.15 
      @tarojs/webpack-runner: 3.2.15 => 3.2.15 
      babel-preset-taro: 3.2.15 => 3.2.15 
      eslint-config-taro: 3.2.15 => 3.2.15 
    npmGlobalPackages:
      typescript: 4.2.3

补充信息

问题和这个一样,可参考看下
zloirock/core-js#583,

Ok, let say in other words: you should use useBuiltIns option of preset-env OR corejs option of runtime, but not together.

@taro-bot2 taro-bot2 bot added F-vue2 Framework - Vue 2 T-h5 Target - 编译到 H5 V-3 Version - 3.x labels Jul 7, 2021
@wanqing19954 wanqing19954 changed the title babel-preset-env 设置 useBuiltIn: 'usage' 会导致 @babel/preset-env 和 @babel/plugin-transform-runtime 都设置了core.js: 3.0, 导致编译报错 babel-preset-taro 设置 useBuiltIn: 'usage' 会导致 @babel/preset-env 和 @babel/plugin-transform-runtime 都设置了core.js: 3.0, 导致编译报错 Jul 8, 2021
@wanqing19954 wanqing19954 changed the title babel-preset-taro 设置 useBuiltIn: 'usage' 会导致 @babel/preset-env 和 @babel/plugin-transform-runtime 都设置了core.js: 3.0, 导致编译报错 babel-preset-taro 设置 useBuiltIns: 'usage' 会导致 @babel/preset-env 和 @babel/plugin-transform-runtime 都设置了core.js: 3.0, 导致编译报错 Jul 8, 2021
@Chen-jj Chen-jj added this to the 3.3.1 milestone Jul 21, 2021
@Chen-jj Chen-jj added the good first issue Good for newcomers label Jul 21, 2021
@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 21, 2021

@wanqing19954 兜兜转转 debug 了半天,原来是 babel 使用 corejs 时把 Webpack buildin 的 global 函数也处理了,但 corejs 里面也会使用到 Webpack 注入的 global,然后就死循环了。

有兴趣了解详情,可以看看这位老哥的回答:zloirock/core-js#743

解决办法正如上述链接所述,把 /\bwebpack\/buildin\b/ exclude 掉,改动随 Taro v3.1 发布。

Anyway,我顺手把 babel-config-taro 的配置文档补了一下,useBuiltIns 参数有改动。可以看看文档:

基础教程 => 配置 => Babel 配置

Chen-jj added a commit that referenced this issue Jul 22, 2021
* fix(babel-preset-taro): 调整 useBuiltIns 的行为,fix #9705

* docs: update readme

* fix(webpack-runner): 使用vue时不使用fast-refresh,fix #9843

* fix: ci
@ccqgithub
Copy link

ccqgithub commented Sep 3, 2021

@Chen-jj 3.3.5版本问题还存在,加了useBuiltIns: "usage", npm run dev:weapp 还会报这个错误。

Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
TypeError: Can't call method on undefined

@hetao1024768
Copy link

@Chen-jj 3.3.19版本问题还存在,taro3 vue3 nutui-taro 加了useBuiltIns: "usage", npm run dev:h5 npm run dev:weapp 还会报这个错误。
image

@Chen-jj
Copy link
Contributor

Chen-jj commented Dec 31, 2021

还有问题的话新开一个 issue 并附上可复现代码吧。只看报错很难推测原因

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-vue2 Framework - Vue 2 good first issue Good for newcomers T-h5 Target - 编译到 H5 V-3 Version - 3.x
Projects
Archived in project
4 participants