When testing locally I was previously running:
"build-live": "nodemon --exec ./node_modules/.bin/ts-node -r dotenv/config -- ./index.ts"
I then figured my Procfile should be something like:
web: ./node_modules/.bin/ts-node -- ./index.ts
But it says module 'typescript' not found, even when it is in package.json
. I read in a few places that ts-node
is not the way to go to deploy to Heroku, so I am not sure what to do.
UPDATE: I think I am supposed to compile it, so I tried:
web: ./node_modules/.bin/tsc --module commonjs --allowJs --outDir build/ --sourceMap --target es6 index.ts && node build/index.js
This succeeds, however when actually running it, a bunch of the libs I'm using get "Cannot find module '...'".
Step 4: Deploying the Node.js app to HerokuClick on the “Create new app”. Open the Deploy tab and scroll to the “Deployment method” section of the tab. Select GitHub as a method. It will show a “Connect to GitHub” option where we add provide our GitHub repository.
Alternatively you can have the TypeScript compile as a postinstall hook and run node build/index.js
as the only Procfile command:
Your package.json
should contain a postinstall hint that gets executed after npm install
and before the node process launches:
"scripts": {
"start": "node build/index.js",
"build": "tsc",
"postinstall": "npm run build"
}
You can then leave your Procfile as is:
web: npm start
This 'build on deploy' approach is documented by Heroku here.
My problem was about missing Typescript npm modules. The Typescript compiler tsc
was not found when deployed the app to Heroku.
The Heroku deploy process (rightly) does not install development dependencies, in my case the Typescript module was part of devDependencies and thus the tsc
command was not running on the Heroku platform.
Add typescript
to dependencies: npm i typescript -s
npm i typescript && npm run tsc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With