【问题标题】:VueJS error on IE11 - SCRIPT1004: Expected ';'IE11 上的 VueJS 错误 - SCRIPT1004: 预期为 ';'
【发布时间】:2020-07-03 00:26:07
【问题描述】:

IE11 - 错误:SCRIPT1004:预期为 ';'

嗨!我的网站适用于除 IE 以外的所有浏览器。我的 babel.config.js 文件:

 module.exports = {
  presets: [
    ['@vue/app', {
      polyfills: [
        'es.promise',
        'es.symbol',
        'es6.array.iterator'
      ]
    }]
  ],
  "plugins": [
    "@babel/plugin-transform-shorthand-properties",
    "@babel/plugin-proposal-object-rest-spread",
    [
      'component',
      {
        libraryName: 'element-ui',
        styleLibraryName: 'theme-chalk'
      }
    ]
  ]
}

--->Console screenshot

--->Debugger screenshot

【问题讨论】:

    标签: javascript vue.js internet-explorer babeljs vue-cli


    【解决方案1】:

    您的调试器屏幕截图显示错误来自 native-toast 包。该包的 GitHub 显示了一个 unresolved issue,其中使用了 for ... of 循环。 IE 不知道如何解释,这是导致 Vue IE SCRIPT1004 错误的常见原因(只是缺少分号)。

    您可以告诉 Vue CLI 转译整个 native-toast 依赖包,这是默认情况下不做的事情。在你的vue.config.js(不是 Babel)中:

    module.exports = {
      transpileDependencies: [
        'native-toast'  
      ]
    }
    

    (注意:transpileDependencies 是一个包名数组[或 RegExp])

    显然,在某些情况下,您可能还需要在 babel.config.js 中使用它(先尝试不使用它):

    module.exports = {
      "presets": [
        '@babel/preset-env'
      ],
    }
    

    参考:

    Vue CLI transpileDependencies

    Vue CLI polyfills guide

    Vue Forum transpileDependencies example

    【讨论】:

    • 非常感谢!我也必须翻译'vue-stripe-checkout'。 ^_^
    • 不客气,很高兴它成功了 :) 您是否必须更改 Babel 配置或者 transpileDependencies 是否足够?
    • transpileDependencies 就够了 =D
    猜你喜欢
    • 1970-01-01
    • 2020-09-09
    • 1970-01-01
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    • 2020-06-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多