Deploy express + typescript as Render web service

Hello- I’ve read over some other posts that have had a similar problem deploying an Express/TypeScript application, and tried the suggested fixes, but am still getting errors.

Here are my variables in settings:
branch - main
root dir - (left blank)
build command - npm ci; npm run build
start command - npm run start

here’s part of my package.json:
“main”: “index.js”,
“scripts”: {
“build”: “npm install && tsc”,
“start”: “node index.js”
}

text of the error:
Nov 27 06:41:02 PM > page-two-server-ts@1.0.0 start /opt/render/project/src
Nov 27 06:41:02 PM > node index.js
Nov 27 06:41:02 PM node:internal/modules/cjs/loader:959
Nov 27 06:41:02 PM throw err;
Nov 27 06:41:02 PM ^
Nov 27 06:41:02 PM Error: Cannot find module ‘/opt/render/project/src/index.js’

But, my index.ts file is indeed in a “src” folder, which is at the main level of the repository. Ideas?

Thanks
-D

I have a similar problem. In your case, I believe that you should try “node ./build/index.js” or “node ./dist/index.js” at your start script.

You can see with it is “build” or “dist” in your tsconfig file at “outDir”.

Hi there,

Thanks for reaching out.

As Manuel suggested, you’re likely compiling your TypeScript into JavaScript in another folder and will need to reference it correctly.

Please let us know if we can assist any further.

Alan

1 Like

Thanks guys! That fixed the problem.

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