IE停止维护 导致 @vue/cli-plugin-babel 编译失败

背景

多个前端vue项目执行npm run build编译时突然出现类似下面的错误

 error  in ./src/views/modelManage/components/edit/field/AddModel.vue?vue&type=script&lang=js&

Module parse failed: Unexpected token (1011:30)
File was processed with these loaders:
 * ./node_modules/cache-loader/dist/cjs.js
 * ./node_modules/thread-loader/dist/cjs.js
 * ./node_modules/babel-loader/lib/index.js
 * ./node_modules/cache-loader/dist/cjs.js
 * ./node_modules/vue-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.

解决方案

  • 修改项目中的.browserslistrc 文件,在"not dead"这一行后面加上IE 11这一行, 例如:

    # 注释是这样写的,以#号开头
    last 1 version #最后的一个版本
    > 1%  #代表全球超过1%使用的浏览器
    maintained node versions #所有还被 node 基金会维护的 node 版本
    not dead
    IE 11
    
  • 或者在package.json中修改配置

    {
      "browserslist": [
        "last 1 version",
        "> 1%",
        "maintained node versions",
        "not dead",
        "IE 11"
      ]
    }
    
  • 如果还不能解决,可以尝试修改babel.config.js:pluginspresets, 例如:

module.exports = {
  presets: [['@vue/cli-plugin-babel/preset'], ['@babel/preset-env']],
  env: {
    development: {
      plugins: [['dynamic-import-node'], [ '@babel/plugin-proposal-optional-chaining' ], [ '@babel/plugin-proposal-nullish-coalescing-operator' ]],
    },
  },
}

原因

微软宣布,在当地时间2022年6月15日永久关闭IE浏览器,至此,这款已经诞生了27年的浏览器正式宣布退出历史舞台。IE 唯一的作用就是下载其他浏览器, 让我们为IE默哀三分钟 😂
在这里插入图片描述

其他更多讨论和解决方案请参考

https://github.com/vuejs/vue-cli/issues/7209
https://github.com/browserslist/browserslist#browsers-data-updating
https://www.zhoulujun.cn/html/webfront/ECMAScript/nodejs/8854.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值