我試圖在 heroku 上部署我的 discord.js 機器人,但我總是遇到錯誤并且機器人崩潰。我的代碼很好,我在我的電腦上運行它,它沒有給出任何錯誤。我按照此鏈接設定了我的 Heroku 應用程式https://devcenter.heroku.com/articles/getting-started-with-nodejs#set-up。我完全按照它說的做了,但我收到了這個錯誤:
2021-10-12T08:15:45.604131 00:00 heroku[web.1]: Starting process with command `npm start`
2021-10-12T08:15:46.708903 00:00 app[web.1]:
2021-10-12T08:15:46.709032 00:00 app[web.1]: > kurumi@1.0.0 start /app
2021-10-12T08:15:46.709036 00:00 app[web.1]: > node index.js
2021-10-12T08:15:46.709036 00:00 app[web.1]:
2021-10-12T08:15:46.772460 00:00 app[web.1]: /app/node_modules/discord.js/src/rest/APIRequest.js:33
2021-10-12T08:15:46.772464 00:00 app[web.1]: agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
2021-10-12T08:15:46.772465 00:00 app[web.1]: ^^^
2021-10-12T08:15:46.772465 00:00 app[web.1]:
2021-10-12T08:15:46.772468 00:00 app[web.1]: SyntaxError: Unexpected token '??='
2021-10-12T08:15:46.772468 00:00 app[web.1]: at wrapSafe (internal/modules/cjs/loader.js:1001:16)
2021-10-12T08:15:46.772468 00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1049:27)
2021-10-12T08:15:46.772471 00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-10-12T08:15:46.772471 00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32)
2021-10-12T08:15:46.772471 00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:12)
2021-10-12T08:15:46.772471 00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19)
2021-10-12T08:15:46.772472 00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:93:18)
2021-10-12T08:15:46.772472 00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/discord.js/src/rest/RESTManager.js:4:20)
2021-10-12T08:15:46.772472 00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14)
2021-10-12T08:15:46.772472 00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-10-12T08:15:46.779715 00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-10-12T08:15:46.779895 00:00 app[web.1]: npm ERR! errno 1
2021-10-12T08:15:46.783479 00:00 app[web.1]: npm ERR! kurumi@1.0.0 start: `node index.js`
2021-10-12T08:15:46.783529 00:00 app[web.1]: npm ERR! Exit status 1
2021-10-12T08:15:46.783595 00:00 app[web.1]: npm ERR!
2021-10-12T08:15:46.783640 00:00 app[web.1]: npm ERR! Failed at the kurumi@1.0.0 start script.
2021-10-12T08:15:46.783698 00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-10-12T08:15:46.786955 00:00 app[web.1]:
2021-10-12T08:15:46.787031 00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-10-12T08:15:46.787064 00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-10-12T08_15_46_784Z-debug.log
2021-10-12T08:15:46.938086 00:00 heroku[web.1]: Process exited with status 1
2021-10-12T08:15:47.109411 00:00 heroku[web.1]: State changed from starting to crashed
2021-10-12T08:15:47.120433 00:00 heroku[web.1]: State changed from crashed to starting
2021-10-12T08:15:50.000000 00:00 app[api]: Build succeeded
2021-10-12T08:15:51.902833 00:00 heroku[web.1]: Starting process with command `npm start`
2021-10-12T08:15:52.879739 00:00 app[web.1]:
2021-10-12T08:15:52.879754 00:00 app[web.1]: > kurumi@1.0.0 start /app
2021-10-12T08:15:52.879755 00:00 app[web.1]: > node index.js
2021-10-12T08:15:52.879755 00:00 app[web.1]:
2021-10-12T08:15:52.943619 00:00 app[web.1]: /app/node_modules/discord.js/src/rest/APIRequest.js:33
2021-10-12T08:15:52.943621 00:00 app[web.1]: agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
2021-10-12T08:15:52.943621 00:00 app[web.1]: ^^^
2021-10-12T08:15:52.943622 00:00 app[web.1]:
2021-10-12T08:15:52.943622 00:00 app[web.1]: SyntaxError: Unexpected token '??='
2021-10-12T08:15:52.943623 00:00 app[web.1]: at wrapSafe (internal/modules/cjs/loader.js:1001:16)
2021-10-12T08:15:52.943623 00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1049:27)
2021-10-12T08:15:52.943624 00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-10-12T08:15:52.943624 00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32)
2021-10-12T08:15:52.943624 00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:12)
2021-10-12T08:15:52.943625 00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19)
2021-10-12T08:15:52.943625 00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:93:18)
2021-10-12T08:15:52.943625 00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/discord.js/src/rest/RESTManager.js:4:20)
2021-10-12T08:15:52.943627 00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14)
2021-10-12T08:15:52.943627 00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-10-12T08:15:52.950345 00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-10-12T08:15:52.950523 00:00 app[web.1]: npm ERR! errno 1
2021-10-12T08:15:52.953970 00:00 app[web.1]: npm ERR! kurumi@1.0.0 start: `node index.js`
2021-10-12T08:15:52.954012 00:00 app[web.1]: npm ERR! Exit status 1
2021-10-12T08:15:52.954061 00:00 app[web.1]: npm ERR!
2021-10-12T08:15:52.954092 00:00 app[web.1]: npm ERR! Failed at the kurumi@1.0.0 start script.
2021-10-12T08:15:52.954134 00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-10-12T08:15:52.956414 00:00 app[web.1]:
2021-10-12T08:15:52.956490 00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-10-12T08:15:52.956517 00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-10-12T08_15_52_954Z-debug.log
2021-10-12T08:15:53.132196 00:00 heroku[web.1]: Process exited with status 1
2021-10-12T08:15:53.198551 00:00 heroku[web.1]: State changed from starting to crashed
2021-10-12T08:16:14.979868 00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gentle-thicket-97709.herokuapp.com request_id=bc0fd458-0a88-4f7f-8fe6-7a21d52e3035 fwd="114.31.4.178" dyno= connect= service= status=503 bytes= protocol=https
2021-10-12T08:16:15.988690 00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gentle-thicket-97709.herokuapp.com request_id=b830f6e2-5525-4310-b415-4e902015b8e3 fwd="114.31.4.178" dyno= connect= service= status=503 bytes= protocol=https
uj5u.com熱心網友回復:
Heroku 的 nodejs 版本非常低,遺憾的是您無法更新它,因此沒有真正的方法來修復它。如果它適用于 djs v12.5.3,您仍然可以在這里運行機器人
uj5u.com熱心網友回復:
使用 heroku 時,您可以在package.jsonwithengines屬性中指定節點版本。您可以嘗試將版本設定為15或更高嗎?
{
"name": "myapp",
"description": "a really cool app",
"version": "1.0.0",
"engines": {
"node": "15.x"
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/318875.html
