1

My NodeJS App is written in Typescript and I am trying to deploy it on Heroku.

I was following a YouTube tutorial.

My app is deployed but it's showing me error. Can anybody tell me what's the issue?

Is it because of the app written in Typescript?

I created a Procfile and added this [web: nodemon src/server.ts] in file. So that heroku knows where to find the server file.

If there is a similar question or answer related to my Question, please do share that link here.

9
  • 1
    I'm doing an app in express-node with typescript and i can relate to this question, and, as far as i know, shouldn't you put in the procfile document server.js instead of server.ts ? Commented Jun 13, 2021 at 20:43
  • @Diego I am new to tyepscript and node, the whole back is written in typescript with extensions ".ts" including the server file. That's why i put server.ts Commented Jun 13, 2021 at 20:51
  • @Diego TypeScript files are .ts files. I don't know why OP isn't just compiling the TypeScript into JavaScript beforehand tho Commented Jun 13, 2021 at 20:51
  • #1 Could you share us the package.json to have an idea of your stack? #2 How do you run in your laptop? npm run dev #3 Do you have the npm run build script in your package.json? #4 npm run build is required to make real js apps using javascript or typescript. #4 If you have this script, I created a server which would help you to deploy your js app in any server like heroku, gcp, aws, azure, etc Commented Jun 13, 2021 at 21:11
  • Thanks @JRichardsz for your response, i ran the "npm run build" command, it created a folder named "dist", but it doesn't contain any package.json file. So, I have to deploy this folder? Commented Jun 13, 2021 at 21:19

2 Answers 2

1

The answer is:

First add all of your config variables in App settings on Heroku. The second is to add your [start and engine] scripts in package.json file

"scripts": {
    "start": "node dist/server",
    "dev": "sucrase-node src/server.ts",
    "build": "sucrase ./src -d ./dist --transforms typescript,imports"
  },enter code here
  "engines": {
    "node": ">=10.0.0"
  },
Sign up to request clarification or add additional context in comments.

1 Comment

I had to change the "start": "node dist/server" to "start": "node ./server". Thanks for the solution!
0

Answer

My script package.json

"scripts": {
    "dev": "ts-node-dev --no-notify --respawn --transpile-only src/index.ts",
    "build": "tsc --build",
    "start": "node dist/index.js",
    "deloy": "git push heroku main",
    "log": "heroku logs --tail"
  },

my Procfile web: npm start

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.