Issues with deploying node typescript

I have a frontend and backend folder in a github repo.
I’m new to typescript, in the backend folder, I created the index.ts and compiled it to index.js in the build folder. The build folder is ignored by git, not sure if it’s the issue
When trying to deploy on Render with
Root Directory: backend
Build Command: npm install && npm run build
Start Command: npm start

It kept failing and saying it can’t find index.js

This is my package.json, might be helpful to understand
“name”: “backend”,
“version”: “1.0.0”,
“description”: “”,
“main”: “./build/index.js”,
“scripts”: {
“start”: “node ./build/index.js”,
“build”: “tsc”
},

Hi sh3242,

Your build command looks like it’s only running yarn, which I believe will only install dependencies. I think you’ll need to add a step to that command.

Give that a try and let me know if it helps.

if not, it could help to provide the relevant error, logs, and your package.json

Regards,

Matt

Hi Matt, thanks for your response, I changed the settings on render to this:
Root Directory: backend
Build Command: npm install && npm run build
Start Command: npm start

And this the the logs I got:

backend@1.0.0 build

Apr 15 11:25:36 AM> tsc

Apr 15 11:25:36 AM

Apr 15 11:25:40 AMsrc/index.ts(1,1): error TS2580: Cannot find name ‘require’. Do you need to install type definitions for node? Try npm i --save-dev @types/node.

Apr 15 11:25:40 AMsrc/index.ts(3,21): error TS7016: Could not find a declaration file for module ‘express’. ‘/opt/render/project/src/backend/node_modules/express/index.js’ implicitly has an ‘any’ type.

Apr 15 11:25:40 AM Try npm i --save-dev @types/express if it exists or add a new declaration (.d.ts) file containing declare module 'express';

Apr 15 11:25:40 AMsrc/index.ts(4,18): error TS7016: Could not find a declaration file for module ‘cors’. ‘/opt/render/project/src/backend/node_modules/cors/lib/index.js’ implicitly has an ‘any’ type.

Apr 15 11:25:40 AM Try npm i --save-dev @types/cors if it exists or add a new declaration (.d.ts) file containing declare module 'cors';

Apr 15 11:25:40 AMsrc/index.ts(16,16): error TS2580: Cannot find name ‘process’. Do you need to install type definitions for node? Try npm i --save-dev @types/node.

Apr 15 11:25:40 AMsrc/index.ts(26,38): error TS7006: Parameter ‘req’ implicitly has an ‘any’ type.

Apr 15 11:25:40 AMsrc/index.ts(26,43): error TS7006: Parameter ‘res’ implicitly has an ‘any’ type.

Apr 15 11:25:40 AMsrc/index.ts(45,43): error TS7006: Parameter ‘req’ implicitly has an ‘any’ type.

Apr 15 11:25:40 AMsrc/index.ts(45,48): error TS7006: Parameter ‘res’ implicitly has an ‘any’ type.

Apr 15 11:25:40 AMsrc/index.ts(61,42): error TS7006: Parameter ‘req’ implicitly has an ‘any’ type.

Apr 15 11:25:40 AMsrc/index.ts(61,46): error TS7006: Parameter ‘res’ implicitly has an ‘any’ type.

Apr 15 11:25:40 AMsrc/index.ts(87,41): error TS7006: Parameter ‘req’ implicitly has an ‘any’ type.

Apr 15 11:25:40 AMsrc/index.ts(87,45): error TS7006: Parameter ‘res’ implicitly has an ‘any’ type.

Apr 15 11:25:40 AMsrc/index.ts(108,44): error TS7006: Parameter ‘req’ implicitly has an ‘any’ type.

Apr 15 11:25:40 AMsrc/index.ts(108,48): error TS7006: Parameter ‘res’ implicitly has an ‘any’ type.

Apr 15 11:25:40 AMsrc/recipe-api.ts(2,16): error TS2580: Cannot find name ‘process’. Do you need to install type definitions for node? Try npm i --save-dev @types/node.

Apr 15 11:25:40 AM==> Build failed :disappointed:

And this is my package.json
{
“name”: “backend”,
“version”: “1.0.0”,
“description”: “”,
“main”: “index.js”,
“scripts”: {
“build”: “tsc”,
“start”: “node build/index.js”
},
“keywords”: ,
“author”: “”,
“license”: “ISC”,
“dependencies”: {
“@prisma/client”: “^5.9.1”,
“cors”: “^2.8.5”,
“dotenv”: “^16.4.5”,
“express”: “^5.0.0-beta.1”,
“prisma”: “^5.9.1”
},
“devDependencies”: {
“@types/cors”: “^2.8.17”,
“@types/express”: “^4.17.21”,
“@types/node”: “^20.11.20”,
“nodemon”: “^3.0.3”,
“ts-node”: “^10.9.2”,
“typescript”: “^5.4.5”
}
}

Hey Matt, I think I probably solved the issue but not totally, I made 2 changes:
1: I changed the outDir:./build to outDir:build in tsconfig.json
2. I followed a tutorial before this time to set the environment variable like this:

  • DATABASE_URL: URL from ElephantSQL (change postgres:postgresql:)
  • NODE_ENV: “production”

I didn’t add NODE_ENV this time and I didn’t change postgres to postgresql(just trying it out but I don’t understand why)

I think I understand the first change because I added the wrong path to access build folder I guess.

I don’t quite understand the second change and don’t even know if it’s relevant, do you have experience with it?

Hi sh3242,

I can’t say I’ve ever used Elephant sql. Looks like their docs mention postgres://...:https://www.elephantsql.com/docs/index.html

Perhaps the node library or ORM you’re using requires postgresql://...?

Anyway, glad to hear you’re up and running. Thanks for the follow-up!

Regards,

Matt

Thank you, Matt. Really appreciate your responses

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.