title: Nuxt and Axios - javaScript heap out of memory
body: <p>I don't know what is going on with Nuxt and Axios, after the user session expire and the API returnsa a status 401, if I reload the page it get stuck and after a couple of minutes it return this error in console:</p>
  
  <pre><code>&lt;--- Last few GCs ---&gt;
  
  [85937:0x108000000]  4259490 ms: Mark-sweep 2025.8 (2050.9) -&gt; 2025.0 (2050.9) MB, 1638.9 / 0.0 ms  (average mu = 0.111, current mu = 0.006) allocation failure scavenge might not succeed
  [85937:0x108000000]  4261994 ms: Mark-sweep 2025.9 (2050.9) -&gt; 2025.0 (2051.2) MB, 2495.0 / 0.0 ms  (average mu = 0.050, current mu = 0.004) allocation failure scavenge might not succeed
  
  
  &lt;--- JS stacktrace ---&gt;
  
  ==== JS stack trace =========================================
  
      0: ExitFrame [pc: 0x100950919]
      1: StubFrame [pc: 0x1009523cb]
  Security context: 0x0e33ea8c08d1 &lt;JSObject&gt;
      2: exec [0xe33ea8d49b1](this=0x0e3338818389 &lt;JSRegExp &lt;String[#10]: %[dfijoOs]&gt;&gt;,0x0e33ea8f5d61 &lt;String[#51]: Cannot %s headers after they are sent to the client&gt;)
      3: [Symbol.match] [0xe33ea8d4899](this=0x0e3338818389 &lt;JSRegExp &lt;String[#10]: %[dfijoOs]&gt;&gt;,0x0e33ea8f5d61 &lt;String[#51]: Cannot %s headers after they are sen...
  
  FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
  
  Writing Node.js report to file: report.20200403.123410.85937.0.001.json
  Node.js report completed
   1: 0x100080c68 node::Abort() [/Users/aaa/.nvm/versions/node/v12.16.1/bin/node]
   2: 0x100080dec node::errors::TryCatchScope::~TryCatchScope() [/Users/aaa/.nvm/versions/node/v12.16.1/bin/node]
   3: 0x100185167 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Users/aaa/.nvm/versions/node/v12.16.1/bin/node]
   4: 0x100185103 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/aaa/.nvm/versions/node/v12.16.1/bin/node]
   5: 0x10030b2f5 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/Users/aaa/.nvm/versions/node/v12.16.1/bin/node]
   6: 0x10030c9c4 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/Users/aaa/.nvm/versions/node/v12.16.1/bin/node]
   7: 0x100309837 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/Users/aaa/.nvm/versions/node/v12.16.1/bin/node]
   8: 0x1003077fd v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Users/aaa/.nvm/versions/node/v12.16.1/bin/node]
   9: 0x100312fba v8::internal::Heap::AllocateRawWithLightRetry(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/aaa/.nvm/versions/node/v12.16.1/bin/node]
  10: 0x100313041 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/aaa/.nvm/versions/node/v12.16.1/bin/node]
  11: 0x1002e035b v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/Users/aaa/.nvm/versions/node/v12.16.1/bin/node]
  12: 0x100618718 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/Users/aaa/.nvm/versions/node/v12.16.1/bin/node]
  13: 0x100950919 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/Users/aaa/.nvm/versions/node/v12.16.1/bin/node]
  14: 0x1009523cb Builtins_SubString [/Users/aaa/.nvm/versions/node/v12.16.1/bin/node]
  </code></pre>
  
  <p>The Node version I'm using is the <strong>12.16.1</strong></p>
  
  <p>The Axios Plugin file is this:</p>
  
  <pre><code>import https from 'https'
  
  export default function({ $axios, redirect }) {
    const agent = new https.Agent({
      rejectUnauthorized: false
    })
  
    // Axios default options
    $axios.defaults.baseURL = process.env.apiBaseUrl
    $axios.setHeader('Content-Type', 'application/json')
    $axios.setHeader('Access-Control-Allow-Origin', '*')
  
    $axios.onRequest(config =&gt; {
      config.httpsAgent = agent
    })
  
    $axios.onError(({ response }) =&gt; {
      const statusCode = response.status
      const data = response.data
      switch (statusCode) {
        case 401:
          redirect('/session-expired')
          break
        case 404:
          let path = '/404'
          redirect(path)
          break
        case 500:
          return this.$nuxt.error({ statusCode })
        default:
          return false
      }
    })
  }
  </code></pre>
  
  <p>The <code>@nuxt/axios</code> version is the latest: 5.9.7.</p>
  
  <p>I think the issue is in the <code>onError</code> method because as soon as I comment it out I can run the application... Why does it happen?</p>