gpt4 book ai didi

javascript - 在 Azure 上上传时为 "Unexpected token ="

转载 作者:行者123 更新时间:2023-12-02 22:45:39 25 4
gpt4 key购买 nike

我面临着一个以前从未遇到过的问题。我正在开发一个由 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 相同:-)

最佳答案

在普通的 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,并且不应该在任何地方工作。

关于javascript - 在 Azure 上上传时为 "Unexpected token =",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58413149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com