ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

升级`HBuilder X`版本到`2.7.5.20200519`后编译报错`@babel/polyfill` is deprecated.md

2020-05-26 16:05:02  阅读:1463  来源: 互联网

标签:md useBuiltIns cli babel js 报错 polyfill runtime


目录

升级后编译报错@babel/polyfill is deprecated

缘由

  1. 升级HBuilder X版本到2.7.5.20200519

  2. 按照191031 - 部分手机出现或低版本Chrome异常"object.assign is not a function".md 进行修改

    外链地址

    1. 参考"解决方案5:[√有效的 最终采用的方案] - 修改uniapp-cli 编译工具的源码"
    2. 打开HBuilderX\Bin\plugins\uniapp-cli\babel.config.js
    3. 修改useBuiltIns: process.env.UNI_PLATFORM === 'h5' ? 'usage' : 'entry'useBuiltIns: 'entry'
  3. 然后开始编译项目

  4. 结果出现错误信息

错误信息详情

13:31:24.838 请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。
13:31:24.844 正在编译中...
13:31:26.474  INFO  Starting development server...
13:31:30.105   `@babel/polyfill` is deprecated. Please, use required parts of `core-js`
13:31:30.110   and `regenerator-runtime/runtime` separately
13:31:41.245 文件查找失败:'@babel/polyfill' at main.js:1

相关线索

  1. 通过对比工具对比2个新旧文件夹

    1. HBuilderX\Bin\update\backup\plugins
    2. HBuilderX\Bin\plugins
  2. 发现plugins\uniapp-cli\package.json里有"引用的类库"版本变更了

    1. "@vue/cli-plugin-babel": "3.5.1",升级到了"~4.2.0",
    2. "caniuse-lite": "^1.0.30001038", 升级到了"^1.0.30001061"
    3. "@dcloudio/vue-cli-plugin-uni": "^2.0.0-26820200330001",升级到了27520200518001
  3. plugins\uniapp-cli\node_modules\@babel\plugin-transform-runtime\lib\index.js

      if (has(options, "useBuiltIns")) {
        if (options.useBuiltIns) {
          throw new Error("The 'useBuiltIns' option has been removed. The @babel/runtime " + "module now uses builtins by default.");
        } else {
          throw new Error("The 'useBuiltIns' option has been removed. Use the 'corejs'" + "option to polyfill with `core-js` via @babel/runtime.");
        }
      }
    
      if (has(options, "polyfill")) {
        if (options.polyfill === false) {
          throw new Error("The 'polyfill' option has been removed. The @babel/runtime " + "module now skips polyfilling by default.");
        } else {
          throw new Error("The 'polyfill' option has been removed. Use the 'corejs'" + "option to polyfill with `core-js` via @babel/runtime.");
        }
      }
    
      if (has(options, "moduleName")) {
        throw new Error("The 'moduleName' option has been removed. @babel/transform-runtime " + "no longer supports arbitrary runtimes. If you were using this to " + "set an absolute path for Babel's standard runtimes, please use the " + "'absoluteRuntime' option.");
      }
  4. plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\lib\h5\index.js

        const beforeCode = (useBuiltIns === 'entry' ? 'import \'@babel/polyfill\';' : '') +
          `import 'uni-pages';import 'uni-${process.env.UNI_PLATFORM}';`
  5. Browser Compatibility | Vue CLI

    f the dependency ships ES5 code, but uses ES6+ features without explicitly listing polyfill requirements (e.g. Vuetify): Use useBuiltIns: 'entry' and then add import 'core-js/stable'; import 'regenerator-runtime/runtime'; to your entry file. This will import ALL polyfills based on your browserslist targets so that you don't need to worry about dependency polyfills anymore, but will likely increase your final bundle size with some unused polyfills.

解决方案

  1. 打开plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\lib\h5\index.js
  2. 修改const beforeCode = (useBuiltIns === 'entry' ? 'import \'@babel/polyfill\';' : '') +
  3. const beforeCode = (useBuiltIns === 'entry' ? 'import \'core-js/stable\'; import \'regenerator-runtime/runtime\';' : '') +

标签:md,useBuiltIns,cli,babel,js,报错,polyfill,runtime
来源: https://www.cnblogs.com/AsionTang/p/12966128.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有