title: Heroku - FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
body: <p>Trying to deploy my app to Heroku (free Dyno) I keep getting an Error <code>FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory</code>. </p>
  
  <p>I've already tried to set <code>node --optimize_for_size --max_old_space_size=460 --gc_interval=100</code> as it's recommended in Heroku FAQ Support but it doesn't seem to help here. </p>
  
  <p>My app runs well on my local Windows machine but on Heroku, the error pops up no matter what I do. </p>
  
  <p>It crashes not on the stage of starting the script but on <code>tsc</code> compiling. </p>
  
  <p>Maybe I've been using node options in a wrong place or something but I guess this approach doesn't work in my case for some reason. </p>
  
  <p>Has anyone got into the same problem on Heroku and how did you solve it? </p>
  
  <p>logging</p>
  
  <pre><code>2020-05-25T10:10:48.311880+00:00 heroku[web.1]: Starting process with command `npm run heroku`
  2020-05-25T10:10:52.925897+00:00 app[web.1]: 
  2020-05-25T10:10:52.925919+00:00 app[web.1]: &gt; express-backend@1.0.0 heroku /app
  2020-05-25T10:10:52.925937+00:00 app[web.1]: &gt; node --optimize_for_size --max_old_space_size=460 --gc_interval=100&amp;&amp;npm-run-all clean compile copy start
  2020-05-25T10:10:52.925938+00:00 app[web.1]: 
  2020-05-25T10:10:54.329357+00:00 app[web.1]: 
  2020-05-25T10:10:54.329371+00:00 app[web.1]: &gt; express-backend@1.0.0 clean /app
  2020-05-25T10:10:54.329372+00:00 app[web.1]: &gt; rm -rf ./dist
  2020-05-25T10:10:54.329372+00:00 app[web.1]: 
  2020-05-25T10:10:55.482684+00:00 app[web.1]: 
  2020-05-25T10:10:55.482694+00:00 app[web.1]: &gt; express-backend@1.0.0 compile /app
  2020-05-25T10:10:55.482695+00:00 app[web.1]: &gt; tsc
  2020-05-25T10:10:55.482695+00:00 app[web.1]: 
  2020-05-25T10:11:13.835222+00:00 app[web.1]: 
  2020-05-25T10:11:13.835249+00:00 app[web.1]: &lt;--- Last few GCs ---&gt;
  2020-05-25T10:11:13.835250+00:00 app[web.1]: lu[70:0x44b09a0]    17193 ms: Mark-sweep 255.8 (257.3) -&gt; 255.0 (257.6) MB, 260.7 / 0.0 ms  (+ 0.0 ms in 3 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 278 ms) (average mu = 0.123, current mu = 0.062) allocation failure[70:0x44b09a0]    17326 ms: Mark-sweep 256.1 (257.6) -&gt; 255.8 (257.6) MB, 83.2 / 0.0 ms  (+ 25.2 ms in 12 steps since start of marking, biggest step 3.2 ms, walltime since start of marking 133 ms) (average mu = 0.145, current mu = 0.185) allocation failur
  2020-05-25T10:11:13.835251+00:00 app[web.1]: 
  2020-05-25T10:11:13.835251+00:00 app[web.1]: &lt;--- JS stacktrace ---&gt;
  2020-05-25T10:11:13.835251+00:00 app[web.1]: 
  2020-05-25T10:11:13.835252+00:00 app[web.1]: ==== JS stack trace =========================================
  2020-05-25T10:11:13.835252+00:00 app[web.1]: 
  2020-05-25T10:11:13.835253+00:00 app[web.1]:     0: ExitFrame [pc: 0x13c5b79]
  2020-05-25T10:11:13.835253+00:00 app[web.1]: Security context: 0x01b71b3008d1 &lt;JSObject&gt;
  2020-05-25T10:11:13.835255+00:00 app[web.1]:     1: addJSDocComment(aka addJSDocComment) [0xd947801e629] [/app/node_modules/typescript/lib/tsc.js:~15330] [pc=0x11ea5812c367](this=0x39366b7804b1 &lt;undefined&gt;,0x0ad037f13561 &lt;Node map = 0xfdad2eb2b19&gt;)
  2020-05-25T10:11:13.835256+00:00 app[web.1]:     2: parseTypeMember(aka parseTypeMember) [0xd9478020029] [/app/node_modules/typescript/lib/tsc.js:~16687] [pc=0x11ea5818c740](this=0x39366b7804b1 &lt;undefined&gt;)...
  2020-05-25T10:11:13.835256+00:00 app[web.1]: 
  2020-05-25T10:11:13.835432+00:00 app[web.1]: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
  2020-05-25T10:11:13.835433+00:00 app[web.1]: 
  2020-05-25T10:11:13.848262+00:00 app[web.1]: Writing Node.js report to file: report.20200525.101113.70.0.001.json
  2020-05-25T10:11:13.848264+00:00 app[web.1]: Node.js report completed
  2020-05-25T10:11:13.848539+00:00 app[web.1]:  1: 0xa09830 node::Abort() [node]
  2020-05-25T10:11:13.848757+00:00 app[web.1]:  2: 0xa09c55 node::OnFatalError(char const*, char const*) [node]
  2020-05-25T10:11:13.852130+00:00 app[web.1]:  3: 0xb7d71e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
  2020-05-25T10:11:13.852131+00:00 app[web.1]:  4: 0xb7da99 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
  2020-05-25T10:11:13.852132+00:00 app[web.1]:  5: 0xd2a1f5  [node]
  2020-05-25T10:11:13.852132+00:00 app[web.1]:  6: 0xd2a886 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [node]
  2020-05-25T10:11:13.852133+00:00 app[web.1]:  7: 0xd37105 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
  2020-05-25T10:11:13.852542+00:00 app[web.1]:  8: 0xd37fb5 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
  2020-05-25T10:11:13.856595+00:00 app[web.1]:  9: 0xd3aa6c v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
  2020-05-25T10:11:13.856597+00:00 app[web.1]: 10: 0xd0163b v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
  2020-05-25T10:11:13.856598+00:00 app[web.1]: 11: 0x104300e v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
  2020-05-25T10:11:13.856599+00:00 app[web.1]: 12: 0x13c5b79  [node]
  2020-05-25T10:11:13.883615+00:00 app[web.1]: Aborted
  2020-05-25T10:11:13.887422+00:00 app[web.1]: npm ERR! code ELIFECYCLE
  2020-05-25T10:11:13.887588+00:00 app[web.1]: npm ERR! errno 134
  2020-05-25T10:11:13.888930+00:00 app[web.1]: npm ERR! express-backend@1.0.0 compile: `tsc`
  2020-05-25T10:11:13.889100+00:00 app[web.1]: npm ERR! Exit status 134
  2020-05-25T10:11:13.889247+00:00 app[web.1]: npm ERR! 
  2020-05-25T10:11:13.889249+00:00 app[web.1]: npm ERR! Failed at the express-backend@1.0.0 compile script.
  2020-05-25T10:11:13.889411+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  2020-05-25T10:11:13.899422+00:00 app[web.1]: 
  2020-05-25T10:11:13.900471+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
  2020-05-25T10:11:13.901218+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-05-25T10_11_13_890Z-debug.log
  2020-05-25T10:11:13.913416+00:00 app[web.1]: ERROR: "compile" exited with 134.
  2020-05-25T10:11:13.919863+00:00 app[web.1]: npm ERR! code ELIFECYCLE
  2020-05-25T10:11:13.920329+00:00 app[web.1]: npm ERR! errno 1
  2020-05-25T10:11:13.921443+00:00 app[web.1]: npm ERR! express-backend@1.0.0 heroku: `node --optimize_for_size --max_old_space_size=460 --gc_interval=100&amp;&amp;npm-run-all clean compile copy start`
  2020-05-25T10:11:13.921603+00:00 app[web.1]: npm ERR! Exit status 1
  2020-05-25T10:11:13.921779+00:00 app[web.1]: npm ERR! 
  2020-05-25T10:11:13.921933+00:00 app[web.1]: npm ERR! Failed at the express-backend@1.0.0 heroku script.
  2020-05-25T10:11:13.922075+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  2020-05-25T10:11:13.934678+00:00 app[web.1]: 
  2020-05-25T10:11:13.935097+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
  2020-05-25T10:11:13.935307+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-05-25T10_11_13_922Z-debug.log
  2020-05-25T10:11:14.015702+00:00 heroku[web.1]: Process exited with status 1
  </code></pre>
  
  <p>package.json</p>
  
  <pre><code>{
    "name": "express-backend",
    "version": "1.0.0",
    "description": "",
    "main": "./dist/server.js",
    "scripts": {
      "prebuild": "npm-run-all -s clean",
      "predev": "npm-run-all -s clean",
      "clean": "rm -rf ./dist",
      "start": "node --optimize_for_size --max_old_space_size=460 --gc_interval=100 ./dist/server.js",
      "compile": "tsc",
      "copy": "cpy src/graphql/schemas/*.graphql dist/graphql/schemas --no-overwrite",
      "build": "tsc&amp;&amp;npm run copy",
      "dev": "tsc-watch --onSuccess \"npm-run-all -s copy start\"",
      "heroku": "node --optimize_for_size --max_old_space_size=460 --gc_interval=100&amp;&amp;npm-run-all clean compile copy start"
    },
    "config": {
      "node-options": "--optimize_for_size --max_old_space_size=460 --gc_interval=100"
    },
    "engines": {
      "node": "12.16.3",
      "npm": "6.14.4"
    },
    "author": "",
    "license": "ISC",
    "dependencies": {
      "@types/bcryptjs": "2.4.2",
      "@types/compression": "1.7.0",
      "@types/crypto-js": "3.1.44",
      "@types/express": "4.17.3",
      "@types/graphql": "14.5.0",
      "@types/js-base64": "2.3.1",
      "@types/jsonwebtoken": "8.3.9",
      "@types/mongoose": "5.7.8",
      "@types/validator": "13.0.0",
      "apollo-server-express": "2.11.0",
      "bcryptjs": "2.4.3",
      "body-parser": "1.19.0",
      "compression": "1.7.4",
      "cors": "2.8.5",
      "crypto-js": "4.0.0",
      "dotenv": "8.2.0",
      "express": "4.17.1",
      "googleapis": "39.2.0",
      "graphql": "14.6.0",
      "graphql-middleware": "4.0.2",
      "graphql-shield": "7.2.3",
      "graphql-tools": "4.0.7",
      "js-base64": "2.5.2",
      "jsonwebtoken": "8.5.1",
      "merge-graphql-schemas": "1.7.6",
      "moment": "2.24.0",
      "mongoose": "5.9.6",
      "npm-run-all": "4.1.5",
      "password-validator": "5.0.3",
      "rimraf": "3.0.2",
      "simple-crypto-js": "2.2.0",
      "validator": "13.0.0",
      "winston": "3.2.1",
      "typescript": "3.8.3",
      "cpy-cli": "^3.1.1"
    },
    "devDependencies": {
      "tsc-watch": "^4.2.3"
    }
  }
  </code></pre>
  
  <p>Procfile</p>
  
  <pre><code>web: npm run heroku
  </code></pre>