When I'm trying to deploy my server to Heroku, the build and everything goes fine. Whenever I try to ping my API to check my server status (whether it's up or down), it comes back with an error (server is down). So, I run heroku logs --tail
and this is the output:
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
From my own research, it was suggested I put in a buildpack for TypeScript, the one that comes up on heroku buildpacks:search
is zidizei/typescript. So I installed that, and it didn't work.
Okay, so more research, and I should instead have the heroku node/js buildpack. I ran heroku buildpacks:set heroku/nodejs
and tried that, didn't work. So I switch back to zidizei, everything compiles and builds, except for the server start.
I'm confused as to what's going on, and I think now that I've been trying this for 2 hours I'm completely lost and turned around in documentation.
I know this is a stupid, beginner question, but if y'all could see how many tabs and SO articles I have open, you'd maybe consider pity. :)
Additional steps I've taken:
// 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
Alternatively, are there any strong heroku contenders for hosting an express server and a Postgres DB?
Adding: I noticed that when I entered into the environment using heroku run bash --app <my_app_name>
that the dist folder is being built. Is the solution to point my start script to something like node dist/src/index.js?
Okay, so for anyone else that is reading this.
My solution was:
In package.json
all I had to do was change my start script from
"start": "ts-node src/index.ts",
to
"start": "node dist/src/index.js",
Seems that at some point I got turned around in my documentation and was looking every which way except the obvious one.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.