I have tsc job failing on gitlab ci with
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
The script I'm running is
tsc -p test/tsconfig.json --noEmit
What I've tried so far is to increase max-old-space-size via:
cross-env NODE_OPTIONS=--max-old-space-size=8192 yarn print:heapsize && tsc -p test/tsconfig.json --noEmitcross-env NODE_OPTIONS='--max-old-space-size=8192' yarn print:heapsize && tsc -p test/tsconfig.json --noEmit (just extra quotes around var)node --max-old-space-size=8192 ./node_modules/.bin/tsc -p test/tsconfig.json --noEmitOptions #1 and #2 doesn't work, and #3 works fine, but it doesn't sound okay to me to run the binary and pass param to the node cli
So my question is - how do I set max-old-spce-size for tsc via env variables or maybe there is another good way to do it?
yarn print:heapsize is the script I used to check current size - it shows 8gb for both #1 and #2 here it is:
"print:heapsize": "node -e \"console.log('🔥 Current heap size:', (require('v8').getHeapStatistics().total_available_size / 1024 / 1024 / 1024).toFixed(2), 'Gb')\""
The first two options fail because the environment variable NODE_OPTIONS=--max-old-space-size=8192 applies only to the first command (yarn print:heapsize) that is before &&.
If you remove yarn print:heapsize && the environment will apply to the compilation command as expected:
cross-env NODE_OPTIONS=--max-old-space-size=8192 tsc -p test/tsconfig.json --noEmit
tsc is deprecated but you can use ts-node with --max-old-space-size in NODE_OPTIONS
Add this options in your package.json
{
"scripts": {
"start": "NODE_OPTIONS='--max-old-space-size=8192' ts-node index.ts"
}
}