I have a problem with deploying my nodejs application to Heroku. i know that i can't push my application with index.ts i have to parse my code to js so i write the command "postinstall": "tsc" but it looks that is not works
When i try push my application to Heroku i get the information:
> server@1.0.0 postinstall /tmp/build_82163065
remote: > tsc
remote:
remote: sh: 1: tsc: not found
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! syscall spawn
remote: npm ERR! file sh
remote: npm ERR! errno ENOENT
remote: npm ERR! server@1.0.0 postinstall: `tsc`
remote: npm ERR! spawn ENOENT
remote: npm ERR!
remote: npm ERR! Failed at the server@1.0.0 postinstall script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.T0pSN/_logs/2021-03-28T16_47_55_171Z-debug.log
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here:
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote: If you're stuck, please submit a ticket so we can help:
remote: https://help.heroku.com/
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
My package.json
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"engines": {
"node": "14.15.1"
},
"scripts": {
"start": "node dist/index.js",
"postinstall": "tsc"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/cors": "^2.8.10",
"@types/express": "^4.17.11",
"@types/mongoose": "^5.10.4",
"@types/node": "^14.14.35",
"ts-node": "^9.1.1",
"ts-node-dev": "^1.1.6"
},
"dependencies": {
"@types/dotenv": "^8.2.0",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"mongoose": "^5.12.2"
}
}
Procfile:
web: node dist/index.js
i have read tutorial from this site: https://medium.com/developer-rants/deploying-typescript-node-js-applications-to-heroku-81dd75424ce0
i installed typescript to dependencies and the application was successfully uploaded, but when i enter to my page i get Application error:( In the heroku logs --tail is the information:
ReferenceError: exports is not defined
at file:///app/dist/index.js:24:23
at ModuleJob.run (internal/modules/esm/module_job.js:152:23)
at async Loader.import (internal/modules/esm/loader.js:166:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)
Process exited with status 1
State changed from starting to crashed
at=error code=H10 desc="App crashed" method=GET path="/" host=memories258.herokuapp.com request_id=6fed263e-7425-4c59-ac9a-8ad5f3fdbf88 fwd="193.192.179.52" dyno= connect= service= status=503 bytes= protocol=https
at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=memories258.herokuapp.com request_id=e45d9b0b-0974-44f5-9e36-c67d8989e446 fwd="193.192.179.52" dyno= connect= service= status=503 bytes= protocol=https
finally its working now. I removed "type": "module",
from package.json
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.