There are a few questions on this already but I have not seen anyone with compilation as slow as mine.
I have a node/express project:
ls src/**/*.ts | wc -l
25
cat src/**/*.ts | wc -l
2618
It's very small. 25 files comprising about 2600 lines of code.
When I run:
tsc --diagnostics
from the root of the project folder (which contains tsconfig.json
and src/
)
I get:
Files: 1629 <---- what??
Lines: 2347286
Identifiers: 1749641
Symbols: 997960
Types: 245321
Instantiations: 70082
Memory used: 1820643K <---- what??
I/O read: 1.08s
I/O write: 0.02s
Parse time: 11.13s
Bind time: 4.24s
Check time: 9.11s
Emit time: 0.14s
Total time: 24.62s
Why are so many files used? It takes up so much memory and time which just doesn't seem right for such a small project. It takes about 6 minutes to run on a less powerful machine and I need to set the memory limit to be higher. exclude
doesn't seem to be working and my suspicion is that typescript is compiling my whole node_modules
folder. I have tried as many glob patterns as I could think of to exclude, and I updated my config to es2022
as per this answer.
edit: I have tried adding:
"types": [],
"skipLibCheck": true
and it makes no difference on time, memory, or files used.
package.json:
{
"name": "server",
"version": "0.0.1",
"description": "audio diary server",
"main": "./build/src/index.js",
"type": "module",
"devDependencies": {
"@types/cron": "^2.0.0",
"@types/jsonwebtoken": "^8.5.9",
"@types/jwk-to-pem": "^2.0.1",
"@types/multer": "^1.4.7",
"@types/node": "^18.7.18",
"@types/node-fetch": "^2.6.3",
"@types/passport": "^1.0.7",
"@types/passport-google-oauth2": "^0.1.4",
"@typescript-eslint/eslint-plugin": "^5.37.0",
"@typescript-eslint/parser": "^5.37.0",
"eslint": "^8.23.1",
"eslint-plugin-react": "^7.31.8",
"sucrase": "^3.29.0",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0",
"typescript": "^5.0.4"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.32.0",
"@mailchimp/mailchimp_marketing": "^3.0.80",
"@sendgrid/mail": "^7.7.0",
"aws-sdk": "^2.1183.0",
"axios": "^0.27.2",
"cors": "^2.8.5",
"cron": "^2.1.0",
"dotenv": "^16.0.1",
"express": "^4.17.1",
"filereader": "^0.10.3",
"fs": "^0.0.1-security",
"get-audio-duration": "^3.1.1",
"googleapis": "^92.0.0",
"jsonwebtoken": "^8.5.1",
"jwk-to-pem": "^2.0.5",
"morgan": "^1.10.0",
"multer": "^1.4.5-lts.1",
"mysql": "^2.14.1",
"openai": "^3.2.1",
"reflect-metadata": "^0.1.10",
"typeorm": "0.2.41"
},
}
tsconfig.json
{
"compilerOptions": {
"lib": ["es2022", "dom"],
"module": "es2022",
"moduleResolution": "node",
"target": "es2022",
"outDir": "./build",
"rootDir": "./src",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"exclude": ["node_modules"],
"include": ["src/**/*"]
}