2

I am building a REST-Api with Express in Typescript and I am experiencing weird behavior from the Typescript-Compiler. Whenever I build the project via tsc -b locally on my Windows-10 machine, everything compiles fine, but when i run the same command on the exact same project on an Amazon EC2 instance, nothing happens. I see no errors and the console is just doing nothing, until I exit out via CTRL+C. And no, I am not just impatient, letting it run for several minutes has no effect either. It gets even weirder as I am able to compile single files in the root of the project by running tsc index.ts, but only if they are placed in the root folder. My tsconfig looks like that:

{
  "compilerOptions": {
    "lib": [
      "es5",
      "es6"
    ],
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "./build",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "esModuleInterop": true
  }
}

and the file structure of my project is:

package.json
package-lock.json
tsconfig.json
src/
  app.ts
  index.ts
  routes/
  entity/ 

My npm version is: 7.8.0 (on the Amazon EC2 Instance)

My typescript version is: 4.2.4 (on the Amazon EC2 Instance)

niclassic
  • 117
  • 2
  • 7

1 Answers1

0

After further investigation I found out this problem occured due to the rather limited memory the EC2 instance has. The node-command used too much memory and thus freezed the machine. I started researching more and there is actually a flag for node to limit its ram usage (node v8.0+), I found it here.

TL;DR: Typescript compilation took too much memory and as a solution you can limit the ram usage a node process can take:

npx --max-old-space-size=250 tsc -b
niclassic
  • 117
  • 2
  • 7