How do I compile Typescript at Heroku postinstall? How do I compile Typescript at Heroku postinstall? heroku heroku

How do I compile Typescript at Heroku postinstall?


You need to call tsc from an npm script. Otherwise Heroku tries to find a global dependency named tsc.

Create a new npm script in your package.json:

"tsc": "tsc"

now replace "postinstall": "tsc" with:

"postinstall": "npm run tsc"


Spent a while to deploy my simple typescript create-react-app to Heroku. Here what worked for me.

package.json - does not need postinstall at all

In the command line install buildpack for your applicationrun:heroku buildpacks:add zidizei/typescriptheroku buildpacks:add heroku/nodejs

You can also search for buildpacksrun:heroku buildpacks:search typescript

My server looks like that (/root/server.js)

const express = require('express')const app = express()const PORT = process.env.PORT || 3000app.use(express.static('build'));app.listen(PORT, () => console.log(`Listening on port ${PORT}`))

package.json

 "scripts": {    "start": "node server.js",    "build": "react-scripts build",    "test": "react-scripts test",    "eject": "react-scripts eject"  }

Also before pushing to heroku, do run 'npm run build'.

My solution wont work if you gonna use webpack dev server, it must be custom server, in my case it was EXPRESS.


just install typescript as dependency it will work