Search code examples
node.jstypescriptfirebasetsc

TSC command taking 372s to complete


I have a very small TypeScript Firebase repo that I use for cloud functions (totals 6 files in my src directory). The tsc command was taking a really long time to complete so I ran it with --diagnotics and got this output:

functions % tsc --extendedDiagnostics
Files:                         290
Lines of Library:            28331
Lines of Definitions:       110562
Lines of TypeScript:           123
Lines of JavaScript:             0
Lines of JSON:                   0
Lines of Other:                  0
Nodes of Library:           117266
Nodes of Definitions:       336850
Nodes of TypeScript:           659
Nodes of JavaScript:             0
Nodes of JSON:                   0
Nodes of Other:                  0
Identifiers:                167151
Symbols:                    183758
Types:                       53351
Instantiations:              68377
Memory used:               209026K
Assignability cache size:    12195
Identity cache size:           223
Subtype cache size:             34
Strict subtype cache size:       0
I/O Read time:               0.58s
Parse time:                 93.62s
ResolveModule time:          9.01s
ResolveTypeReference time:   1.41s
Program time:              107.81s
Bind time:                  49.14s
Check time:                212.69s
transformTime time:          0.42s
Source Map time:             0.26s
commentTime time:            0.21s
I/O Write time:              0.01s
printTime time:              2.52s
Emit time:                   2.53s
Total time:                372.17s

From what I can see online this seems to be really high. I've Googled around and some have suggested including "typeRoots": [ "node_modules/@types" ] in my tsconfig.json or ensuring include has only my src directory, as well as updating to the latest TS (running 4.4.2) but none of this has helped. I'm not a Node eng so not sure where to start.

In case it helps, here's my tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
    "typeRoots": [ "node_modules/@types" ],
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

Solution

  • After further experimenting, I tried installing the current (non-LTS) build of Node as it explicitly lists arm64 as an architecture (I'm running an M1 Mac), and everything ran blazingly fast.

    Running the bleeding edge version of Node isn't possible for me because Firebase doesn't support it yet, but I found this post which recommends running Terminal in Open in Rosetta mode to circumvent issues like these. This fixed the issue.