在嘗試將 Express TypeScript 服務器部署到 Heroku 時,我遇到了錯誤。我跑了heroku logs --tail,這是輸出:
2021-12-02T21:09:20.152292 00:00 app[web.1]: > backend@1.0.0 start /app
2021-12-02T21:09:20.152292 00:00 app[web.1]: > ts-node src/index.ts
2021-12-02T21:09:20.152292 00:00 app[web.1]:
2021-12-02T21:09:20.164793 00:00 app[web.1]: sh: 1: ts-node: not found
2021-12-02T21:09:20.176470 00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-12-02T21:09:20.176764 00:00 app[web.1]: npm ERR! syscall spawn
2021-12-02T21:09:20.176897 00:00 app[web.1]: npm ERR! file sh
2021-12-02T21:09:20.177050 00:00 app[web.1]: npm ERR! errno ENOENT
2021-12-02T21:09:20.184008 00:00 app[web.1]: npm ERR! backend@1.0.0 start: `ts-node src/index.ts`
2021-12-02T21:09:20.184048 00:00 app[web.1]: npm ERR! spawn ENOENT
2021-12-02T21:09:20.184122 00:00 app[web.1]: npm ERR!
2021-12-02T21:09:20.184186 00:00 app[web.1]: npm ERR! Failed at the backend@1.0.0 start script.
2021-12-02T21:09:20.184240 00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-12-02T21:09:20.189489 00:00 app[web.1]:
2021-12-02T21:09:20.192700 00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-12-02T21:09:20.192779 00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-12-02T21_09_20_184Z-debug.log
2021-12-02T21:09:20.372397 00:00 heroku[web.1]: Process exited with status 1
2021-12-02T21:09:20.745674 00:00 heroku[web.1]: State changed from starting to crashed
根據我自己的研究,有人建議我為 TypeScript 放入一個 buildpack,出現的那個heroku buildpacks:search是 zidizei/typescript。我已經安裝了,但沒有成功。
進一步的研究建議使用 heroku node/js buildpack。我跑了heroku buildpacks:set heroku/nodejs并嘗試了,但沒有成功。所以我切換回zidizei,一切都編譯和構建,除了服務器啟動。
我對問題的根源感到困惑,我想我可能已經轉過身了。
我采取的其他步驟:
// package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "ts-node src/index.ts",
"dev": "ts-node-dev src/index.ts",
"build": "tsc",
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js",
"db:generate-migration": "yarn typeorm -- migrate:generate --config ormconfig.ts --connection --name",
"db:run-migration": "yarn typeorm -- migration:run"
// Procfile
web: npm start
或者,是否有任何強大的 heroku 競爭者來托管快速服務器和 Postgres 資料庫?
添加:我注意到當我使用heroku run bash --app <my_app_name>正在構建的 dist 檔案夾進入環境時。是將我的啟動腳本指向類似的解決方案node dist/src/index.js?
uj5u.com熱心網友回復:
好的,所以對于正在閱讀本文的其他人。
我的解決方案是:
在package.json所有我需要做的就是改變從我做起腳本
"start": "ts-node src/index.ts",
到
"start": "node dist/src/index.js",
似乎在某個時候我在我的檔案中轉身,除了明顯的那個之外,正在尋找每一種方式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/377324.html
