【问题标题】:Vue CLI npm run build throws Syntax Error: Unexpected token - but code looks fineVue CLI npm run build 抛出语法错误:意外的令牌 - 但代码看起来不错
【发布时间】:2021-12-07 16:18:17
【问题描述】:

当我尝试 npm run build 我的 Vue 应用程序时出现以下错误:

Syntax Error: Unexpected token (559:18)
    
      557 |         async, allGroups(), {
      558 |             const: theAttendees = await groupsModule.attendeesFromGroups,
    > 559 |             this: .currentAttendees.push(theAttendees)
          |                   ^
      560 |         }, async, logout(err), {
      561 |             alert() { }
      562 |         } `Logout err : ${err}`);

错误中的代码对我来说毫无意义,所有的逗号都在后面,const:this:,尤其是 alert() { },它根本不反映代码是什么。

这就是代码本身的样子。我看不出有什么问题。

  async allGroups() {
    const theAttendees = await groupsModule.attendeesFromGroups
    this.currentAttendees.push(theAttendees)
  }

  async logout(err){
    alert(`Logout err : ${err}`)
    console.log('DASHBOARD: logout')
    await userModule.logout();
  }

如果有人知道这个语法错误实际上指的是什么,我将非常感谢您的帮助。

【问题讨论】:

  • const theAttendees = await groupsModule.attendeesFromGroups();

标签: javascript syntax-error vue-cli


【解决方案1】:

函数 allGroups() 结束后,您可能会缺少逗号 你的代码会像

 async allGroups() {
  const theAttendees = await groupsModule.attendeesFromGroups();
  this.currentAttendees.push(theAttendees)
 },
  async logout(err){
    alert(`Logout err : ${err}`)
    console.log('DASHBOARD: logout')
     await userModule.logout();
  }

【讨论】:

  • 谢谢,但这不是逗号问题。
【解决方案2】:

注意:这不是问题,看评论,使用Vuex函数,所以不需要括号

const theAttendees = await groupsModule.attendeesFromGroups(); <-- missing paranthesis

【讨论】:

  • 如果这就是问题的全部,最好发表评论并投票关闭作为错字
  • 感谢您的回复,但这不是问题所在。这些函数是通过 Veux 模块导入的,不需要括号。
猜你喜欢
  • 2018-11-19
  • 2019-04-09
  • 2023-01-31
  • 2017-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-12
  • 2020-05-09
相关资源
最近更新 更多