【问题标题】:"Unexpected token =" when upload on Azure在 Azure 上上传时出现“意外令牌 =”
【发布时间】:2019-10-18 14:10:36
【问题描述】:

我遇到了一个以前从未遇到过的问题。 我正在开发一个由 Microsoft Bot Framework 提供支持的聊天机器人,因此我已经在几周前将我的项目上传到 azure,一切正常。

今天我上传了我的项目的新更新,这个版本在我的电脑上完美运行。但是当我上传到 Azure 时,日志会抛出这个错误

SyntaxError: Unexpected token =
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
Wed Oct 16 2019 08:25:08 GMT+0000 (Greenwich Mean Time): Application has thrown an uncaught exception and is terminated:

此错误由“userCourses = {}”第 2 行引发:

class UserProfil {
userCourses = {}
constructor(login, firstname, lastname, lastaccess) {
    this.login = login;

    this.firstname = firstname;
    this.lastname = lastname;
    this.lastaccess = lastaccess;
}
}

module.exports.UserProfil = UserProfil

但它似乎对每个字符都抛出错误,例如“=({”所以这不是特别的行......这个项目完全可以在我的电脑上运行,并且一天前在 AZure 上运行过,所以我真的不知道是什么造成了这个大问题

有人遇到过这种情况吗?

谢谢! :-)

编辑:搜索后,我发现我的计算机运行 Nodejs 版本 12,并且此声明是 Nodejs 12 中的新声明,Azure 可能运行最后一个 LTS 版本(10),这就是它无法运行的原因。我已经在我的电脑上安装了 LTS 版本,抛出的错误和 Azure 一样:-)

【问题讨论】:

  • 另外,使用module.exports = {UserProfil}

标签: javascript node.js azure


【解决方案1】:

在原生 JavaScript 中,您不能像这样定义类属性。你必须做更多类似的事情:

class UserProfil {
  constructor(login, firstname, lastname, lastaccess) {
      this.login = login;

      this.firstname = firstname;
      this.lastname = lastname;
      this.lastaccess = lastaccess;

      this.userCourses = {};
  }
}

module.exports.UserProfil = UserProfil

More information on JavaScript classes here


我不知道为什么这会在你的机器人本地工作,除非有某种在本地完成但在 Azure 中没有完成的编译。但这绝对不是有效的 JavaScript,不应该在任何地方工作。

【讨论】:

  • 经过搜索,是nodeJs 12中的新声明,我已经编辑了帖子levelup.gitconnected.com/whats-new-in-node-12-e00111ffb83f
  • 哇。我对此一无所知! Azure Web 应用程序目前在 Node 10 上运行,因此请务必围绕它进行开发,仅供参考。
  • 这是我在 nodejs 上的第一份工作,所以我保留了我对 Java 的旧做法,所以我在不知道 nodejs 中的一个新事物的情况下初始化所有变量啊哈你的回答帮助我理解这是一个新事物!啊哈谢谢! :-)
  • 没问题!切换语言可能很困难。我们应该在明年某个时候让 Java SDK 不再预览,仅供参考。
  • 很高兴知道这一点! :-)
猜你喜欢
  • 2016-08-06
  • 2018-11-24
  • 1970-01-01
  • 2013-02-11
  • 2021-01-11
  • 2017-12-11
  • 2021-12-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多