【发布时间】:2021-11-02 05:07:44
【问题描述】:
我正在使用 discord.js 版本 12.5.3,我也在为我的项目使用 repli。我不断收到此错误:
这是我的代码:
export default class Deps {
static #instances = new Map();
static get(type) {
return this.#instances.get(type)
?? this.add(type, new type());
}
static add(type, instance) {
return this.#instances
.set(type, instance)
.get(type);
}
}
【问题讨论】:
-
return语句有一个隐含的分号,所以如果get(type)返回一个假值,它不会然后尝试this.add(type, new type())。此外,使用PascalCase进行课程,而不是camelCase。 -
我仍然遇到同样的错误。
-
你运行的是什么版本的 NodeJS?运行
node -v找出答案。 -
根据kangax.github.io/compat-table/es2016plus,
??运算符由 NodeJS 14.0 或更高版本支持。如果您使用--harmony-nullish标志,NodeJS 13 也支持它(您也可能希望启用--harmony-optional-chaining)。如果您使用的是旧版本的 Node,那么您可能应该更新。 -
我使用的是 12.16.1 版本,但我无法更新它,因为没有下载功能。有没有办法通过 shell 或控制台来做到这一点? (非常感谢您到目前为止的帮助)
标签: node.js discord.js