title: Allocation failed - JavaScript heap out of memory
body: <p>I am working on a project which is developing with NextJs and ReactJs. Suddenly this project showing <strong>Allocation failed - JavaScript heap out of memory</strong> problem. I have tried all the resources online but, those are not working for me. I think, maybe something error occurred in next.config.js or webpack but, I am not sure about it.</p>
  
  <blockquote>
    <p><strong>package.json</strong></p>
  </blockquote>
  
  <pre><code>{
    "name": "personal-blog",
    "version": "0.1.0",
    "private": true,
    "scripts": {
      "dev": "next dev",
      "build": "next build",
      "start": "next start"
    },
    "dependencies": {
      "@fortawesome/fontawesome-svg-core": "^1.2.28",
      "@fortawesome/free-brands-svg-icons": "^5.13.0",
      "@fortawesome/free-regular-svg-icons": "^5.13.0",
      "@fortawesome/free-solid-svg-icons": "^5.13.0",
      "@fortawesome/react-fontawesome": "^0.1.9",
      "bootstrap": "^4.4.1",
      "dotenv": "^8.2.0",
      "isomorphic-unfetch": "^3.0.0",
      "moment": "^2.24.0",
      "next": "9.3.5",
      "node-fetch": "^2.6.0",
      "react": "16.13.1",
      "react-bootstrap": "^1.0.1",
      "react-debounce-input": "^3.2.2",
      "react-dom": "16.13.1",
      "react-moment": "^0.9.7"
    },
    "devDependencies": {
      "sass": "^1.26.5"
    }
  }
  </code></pre>
  
  <blockquote>
    <p><strong>next.config.js</strong></p>
  </blockquote>
  
  <pre><code>const webpack = require("webpack");
  require("dotenv").config();
  
  module.exports = {
    webpack: config =&gt; {
      config.node = {
        fs: 'empty'
      }
  
      const env = Object.keys(process.env).reduce((acc, curr) =&gt; {
        acc[`process.env.${curr}`] = JSON.stringify(process.env[curr]);
        return acc;
     }, {});
  
      config.plugins.push(new webpack.DefinePlugin(env));
      return config
    }
  }
  </code></pre>
  
  <blockquote>
    <p><strong>Error in Visual Code terminal</strong></p>
  </blockquote>
  
  <pre><code>&lt;--- Last few GCs ---&gt;
  
  [4562:0x103e3b000]   161295 ms: Mark-sweep 2041.6 (2051.3) -&gt; 2040.7 (2051.3) MB, 3551.0 / 0.0 ms  (average mu = 0.370, current mu = 0.462) allocation failure scavenge might not succeed
  [4562:0x103e3b000]   170945 ms: Mark-sweep 2041.8 (2051.5) -&gt; 2041.2 (2051.5) MB, 8225.9 / 0.2 ms  (average mu = 0.253, current mu = 0.148) allocation failure GC in old space requested
  
  
  &lt;--- JS stacktrace ---&gt;
  
  ==== JS stack trace =========================================
  
      0: ExitFrame [pc: 0x10072e699]
  Security context: 0x3ecf281008a1 &lt;JSObject&gt;
      1: createElement(aka createElement) [0x3ecf3bee16f9] [/Users/pater/Desktop/personal-blog/node_modules/react/cjs/react.development.js:~727] [pc=0x1d716fb9bc21](this=0x3ecfe42004a9 &lt;undefined&gt;,0x3ecffb609dc1 &lt;String[#3]: div&gt;,0x3ecfe4f40389 &lt;Object map = 0x3ecfdd48e531&gt;,0x3ecfe42004a9 &lt;undefined&gt;)
      2: arguments adaptor frame: 2-&gt;3
      3: createElement...
  
  FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
  
  Writing Node.js report to file: report.20200424.120915.4562.0.001.json
  Node.js report completed
   1: 0x100b6a52a node::Abort() (.cold.1) [/usr/local/bin/node]
   2: 0x100081f70 node::FatalError(char const*, char const*) [/usr/local/bin/node]
   3: 0x100082098 node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
   4: 0x10017461d v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
   5: 0x1001745c7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
   6: 0x10028a569 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
   7: 0x10028b8ee v8::internal::Heap::MarkCompactPrologue() [/usr/local/bin/node]
   8: 0x1002894eb v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
   9: 0x100287f93 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
  10: 0x10028f6da v8::internal::Heap::AllocateRawWithLightRetry(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [/usr/local/bin/node]
  11: 0x10028fbd0 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [/usr/local/bin/node]
  12: 0x10026d8c6 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType) [/usr/local/bin/node]
  13: 0x1004bc90e v8::internal::Runtime_AllocateInOldGeneration(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
  14: 0x10072e699 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]
  15: 0x1d716fb9bc21 
  Abort
  </code></pre>