I am trying to deploy a simple nodejs app to heroku but getting the above error. Tried solving it based on the available answers here, but nothing seems to work. Here's what I have tried already:
heroku buildpacks: heroku/nodejs zidizei/typescript
...
"main": "index.js",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.18.1",
"rimraf": "^5.0.5",
},
"devDependencies": {
"@types/express": "^4.17.14",
"@types/node": "^18.11.0"
"nodemon": "^2.0.19",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
},
"scripts": {
"start": "node build/server.js",
"postinstall": "tsc",
"dev": "nodemon server.ts",
"start:server": "ts-node server.ts",
"test": "echo \"Error: no test specified\" && exit 1"
}
...
{
"ts-node": {
"compilerOptions": {
"module": "commonjs"
}
},
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"rootDir": "./",
"outDir": "./build",
"strict": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false,
"moduleResolution":"node",
"skipLibCheck": true
},
"files": [ "./utils/index.d.ts" ]
}
Error I am getting on the build step:
-----> TypeScript app detected
-----> Creating build environment
-----> Installing development dependencies
Installing development node modules (npm)
npm WARN invalid config only="dev" set in command line options
npm WARN invalid config Must be one of: null, prod, production
> rmr@1.0.0 postinstall
> npm run build
> rmr@1.0.0 build
> tsc
sh: 1: tsc: not found
npm notice
npm notice New minor version of npm available! 10.1.0 -> 10.2.3
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v10.2.3>
npm notice Run `npm install -g npm@10.2.3` to update!
npm notice
npm ERR! code 127
npm ERR! path /tmp/build_5663ceba
npm ERR! command failed
npm ERR! command sh -c npm run build
Exhausted all ideas about what I might be doing wrong and looking to get enlightened on the same. Any other things I should try?
Thanks in advance!
Got it working by putting tsc into build instead of postinstall, as heroku calls npm start build. At postinstall stage, it seems, devDependencies are no longer accessible.
...
"scripts": {
"start": "node build/server.js",
"build": "tsc",
"dev": "nodemon server.ts",
"start:server": "ts-node server.ts",
"test": "echo \"Error: no test specified\" && exit 1"
}