Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deploy Typescrpit+Node.js server to render.com

i am trying to deploy my TS+Node.js to render.com and it shows :

`Jun 26 01:51:02 PM ==> Starting service with 'node app.ts' Jun 26 01:51:02 PM internal/process/esm_loader.js:74 Jun 26 01:51:02 PM internalBinding('errors').triggerUncaughtException( Jun 26 01:51:02 PM ^ Jun 26 01:51:02 PM Jun 26 01:51:02 PM TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /opt/render/project/src/app.ts Jun 26 01:51:02 PM at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:71:15) Jun 26 01:51:02 PM at Loader.getFormat (internal/modules/esm/loader.js:104:42) Jun 26 01:51:02 PM at Loader.getModuleJob (internal/modules/esm/loader.js:242:31) Jun 26 01:51:02 PM at async Loader.import (internal/modules/esm/loader.js:176:17) Jun 26 01:51:02 PM at async Object.loadESM (internal/process/esm_loader.js:68:5) { Jun 26 01:51:02 PM code: 'ERR_UNKNOWN_FILE_EXTENSION' Jun 26 01:51:02 PM }

this is my package json

{   "name": "server",   "version": "1.0.0",   "description": "",   "main": "app.ts",   "scripts": {     "start": "ts-node-dev app.ts",     "test": "echo \"Error: no test specified\" && exit 1"   },   "keywords": [],   "author": "",   "license": "ISC",   "devDependencies": {     "@types/cookie-parser": "^1.4.3",     "@types/cookie-session": "^2.0.44",     "@types/cors": "^2.8.13",     "@types/express": "^4.17.17",     "@types/jsonwebtoken": "^9.0.1",     "@types/node-cron": "^3.0.7",     "express": "^4.18.2",     "nodemon": "^2.0.22",     "ts-node": "^10.9.1",     "ts-node-dev": "^2.0.0",     "typescript": "^5.0.3"   },   "dependencies": {     "@sendgrid/mail": "^7.7.0",     "@types/joi": "^17.2.3",     "axios": "^1.4.0",     "bcrypt": "^5.1.0",     "cloudinary": "^1.37.0",     "cookie-parser": "^1.4.6",     "cookie-session": "^2.0.0",     "cors": "^2.8.5",     "dotenv": "^16.0.3",     "joi": "^17.9.1",     "joi-objectid": "^4.0.2",     "jsonwebtoken": "^9.0.0",     "mongodb": "3.6",     "mongoose": "^7.0.3",     "multer": "^1.4.5-lts.1",     "node-cron": "^3.0.2"   } }`

this is my ts.config :

{   "compilerOptions": {    "module": "commonjs",    "esModuleInterop": true,    "target": "es6",    "strict": true,    "moduleResolution": "node",    "sourceMap": true,    "outDir": "dist"  },   "include": ["app.ts"],   "exclude": ["node_modules"] }
like image 364
programmer Avatar asked Sep 14 '26 20:09

programmer


1 Answers

Your TypeScript code needs to be compiled into JavaScript. You can either compile it on our local device or let Render do this for you.

Update the key scripts in your package.json

"scripts": {
    "start": "ts-node-dev app.ts",
    "build": "tsc"
}

In the Render Service Settings add a Build Command...

npm install && npm run build

... and add a Start Command (in your case it's 'dist' as declared in your 'tsconfig')

node dist/server.js

❗ Also, make sure you don’t set the Environment Variable NODE_ENV to 'production', or else npm i won’t install typescript, and tsc will fail.

like image 66
Wilhelm Mauch Avatar answered Sep 16 '26 13:09

Wilhelm Mauch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!