【问题标题】:Heroku Unexpected Token ??=Heroku 意外令牌 ??=
【发布时间】:2022-01-08 14:27:03
【问题描述】:
2021-12-02T02:42:45.888858+00:00 app[worker.1]: /app/node_modules/discord.js/src/rest/APIRequest.js:33
2021-12-02T02:42:45.888875+00:00 app[worker.1]:     agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
2021-12-02T02:42:45.888876+00:00 app[worker.1]:           ^^^
2021-12-02T02:42:45.888876+00:00 app[worker.1]: 
2021-12-02T02:42:45.888877+00:00 app[worker.1]: SyntaxError: Unexpected token '??='

我在尝试启动新的 Discord.JS v13 heroku 机器人时收到此错误。

我的 Procfile 状态: worker: node src/index.js

我添加了我的 .env 并配置了机器人的启动方式,而不是使用 npm start。正如您可能推断的那样,我的代码中的任何地方都没有??=。我该如何解决这个问题?

【问题讨论】:

  • APIRequest.js 是您的代码吗?你能在 linux 环境或 docker 上运行它来复制错误吗?
  • @JRichardsz APIRequest.js 不是我的代码。我不确定如何在 Windows 的 linux/docker 上运行它。但是,它在我的 Windows 环境中运行良好。
  • 它是一个开源存储库吗?你能分享给我们一个mvp吗?
  • @ToasterBath27 请检查答案是否解决了您的问题并将其标记为已接受的答案!

标签: javascript node.js heroku discord.js


【解决方案1】:

错误来自 discord.js,这是因为您使用的是旧版本的 node.js。 logical nullish assignment operator (??=) 只是 available in node v15+

Heroku 表示 “如果引擎中未指定 Node 版本,则将使用 14.x 版本”。你可以在你的package.json 文件中添加一个engines 属性来指定node.js 的版本。作为 discord.js v13 requires node.js v16.6+,您可以添加以下内容:

  "engines": {
    "node": "16.6"
  }

或者请求最新的 v16,添加这个:

  "engines": {
    "node": "16.x"
  }

【讨论】:

    猜你喜欢
    • 2021-02-18
    • 2022-01-17
    • 1970-01-01
    • 2019-08-06
    • 2014-11-29
    • 2018-11-19
    • 2017-04-17
    • 2019-05-26
    • 2014-02-19
    相关资源
    最近更新 更多