Heroku Node.js Discord.js 机器人部署失败
Posted
技术标签:
【中文标题】Heroku Node.js Discord.js 机器人部署失败【英文标题】:Heroku Node.js Discord.js bot deployment failed 【发布时间】:2019-02-16 01:47:22 【问题描述】:我遇到了很多问题。我创建了一个本地 git 存储库,将推荐设置设置为 adviced here,并将机器人使用的所有文件复制到该存储库中。然后我添加了所有文件,提交了更改并推送到 Heroku 存储库。但是没有 GitHub 存储库。我没有创建 GitHub 存储库有一个非常重要的原因,因为机器人令牌位于配置 JSON 文件中,这实际上是源代码的一部分。我不希望该令牌公开可见。
然而,事情的结局并不好。 Heroku 日志说应用程序崩溃是因为没有设置入口点。我只能猜测服务器端的应用程序配置错误,或者传输文件时出错。我可以以某种方式恢复应用程序吗?还是我需要制作全新的应用程序并独立安装所有部件?
Heroku 日志是这样写的:
2018-09-11T13:25:20.012914+00:00 heroku[web.1]: State changed from crashed to starting
2018-09-11T13:25:18.633506+00:00 app[api]: Deploy 338966c1 by user marpolda@gmail.com
2018-09-11T13:25:18.633506+00:00 app[api]: Release v7 created by user marpolda@gmail.com
2018-09-11T13:25:19.000000+00:00 app[api]: Build succeeded
2018-09-11T13:25:26.534154+00:00 heroku[web.1]: Starting process with command `npm start`
2018-09-11T13:25:29.260285+00:00 heroku[web.1]: State changed from starting to crashed
2018-09-11T13:25:29.262057+00:00 heroku[web.1]: State changed from crashed to starting
2018-09-11T13:25:29.246814+00:00 heroku[web.1]: Process exited with status 1
2018-09-11T13:25:29.146268+00:00 app[web.1]: npm ERR! missing script: start
2018-09-11T13:25:29.160586+00:00 app[web.1]:
2018-09-11T13:25:29.160933+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-09-11T13:25:29.161118+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-09-11T13_25_29_151Z-debug.log
2018-09-11T13:25:31.267503+00:00 heroku[web.1]: Starting process with command `npm start`
2018-09-11T13:25:33.607355+00:00 heroku[web.1]: Process exited with status 1
2018-09-11T13:25:33.617718+00:00 heroku[web.1]: State changed from starting to crashed
2018-09-11T13:25:33.549320+00:00 app[web.1]: npm ERR! missing script: start
2018-09-11T13:25:33.555176+00:00 app[web.1]:
2018-09-11T13:25:33.555439+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-09-11T13_25_33_550Z-debug.log
2018-09-11T13:25:33.555355+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-09-11T14:02:26.829754+00:00 heroku[web.1]: State changed from crashed to starting
2018-09-11T14:02:29.197832+00:00 heroku[web.1]: Starting process with command `npm start`
2018-09-11T14:02:32.177929+00:00 heroku[web.1]: Process exited with status 1
2018-09-11T14:02:32.191335+00:00 heroku[web.1]: State changed from starting to crashed
2018-09-11T14:02:32.092366+00:00 app[web.1]: npm ERR! missing script: start
2018-09-11T14:02:32.099124+00:00 app[web.1]:
2018-09-11T14:02:32.099383+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-09-11T14:02:32.099521+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-09-11T14_02_32_094Z-debug.log
我似乎无法找到问题的根源。这是package.json
:
"name": "notch",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts":
"test": "echo \"Error: no test specified\" && exit 1"
,
"author": "CZghost",
"license": "ISC",
"dependencies":
"discord.js": "^11.4.2"
以及对应的package-lock.json
:
"name": "notch",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies":
"async-limiter":
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
"integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg=="
,
"discord.js":
"version": "11.4.2",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-11.4.2.tgz",
"integrity": "sha512-MDwpu0lMFTjqomijDl1Ed9miMQe6kB4ifKdP28QZllmLv/HVOJXhatRgjS8urp/wBlOfx+qAYSXcdI5cKGYsfg==",
"requires":
"long": "^4.0.0",
"prism-media": "^0.0.3",
"snekfetch": "^3.6.4",
"tweetnacl": "^1.0.0",
"ws": "^4.0.0"
,
"long":
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz",
"integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA=="
,
"prism-media":
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-0.0.3.tgz",
"integrity": "sha512-c9KkNifSMU/iXT8FFTaBwBMr+rdVcN+H/uNv1o+CuFeTThNZNTOrQ+RgXA1yL/DeLk098duAeRPP3QNPNbhxYQ=="
,
"safe-buffer":
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
,
"snekfetch":
"version": "3.6.4",
"resolved": "https://registry.npmjs.org/snekfetch/-/snekfetch-3.6.4.tgz",
"integrity": "sha512-NjxjITIj04Ffqid5lqr7XdgwM7X61c/Dns073Ly170bPQHLm6jkmelye/eglS++1nfTWktpP6Y2bFXjdPlQqdw=="
,
"tweetnacl":
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.0.tgz",
"integrity": "sha1-cT2LgY2kIGh0C/aDhtBHnmb8ins="
,
"ws":
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-4.1.0.tgz",
"integrity": "sha512-ZGh/8kF9rrRNffkLFV4AzhvooEclrOH0xaugmqGsIfFgOE/pIz4fMc4Ef+5HSQqTEug2S9JZIWDR47duDSLfaA==",
"requires":
"async-limiter": "~1.0.0",
"safe-buffer": "~5.1.0"
【问题讨论】:
【参考方案1】:上面写着2018-09-11T14:02:32.177929+00:00 heroku[web.1]: Process exited with status 1
2018-09-11T14:02:32.191335+00:00 heroku[web.1]: State changed from starting to crashed
2018-09-11T14:02:32.092366+00:00 app[web.1]: npm ERR! missing script: start
这意味着它正在你的 package.json 文件中寻找一个名为“start”的脚本。通常,“开始”脚本仅表示“node *file_name*
”。
在您的 package.json 文件中,添加 "scripts":
"start": "node *your main app filename*",
关于“再次安装所有内容”的问题,我不太明白。尝试添加我提到的脚本,将它们提交到 git 并查看它是否可以解决问题。
【讨论】:
谢谢,它解决了这个问题。还添加了worker
并将 Heroku 进程切换为运行此测功机,从而使应用程序连续运行。正是我需要的。
太棒了。很高兴我能提供帮助:)以上是关于Heroku Node.js Discord.js 机器人部署失败的主要内容,如果未能解决你的问题,请参考以下文章
我正在尝试在 heroku 上部署我的 node.js discord 机器人,但我不断收到错误
我的 Heroku Discord 机器人离线 - discord.js