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

升级后编译报错@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\';' : '') +
posted @ 2020-05-26 15:57  Asion Tang  阅读(3575)  评论(0编辑  收藏  举报