Allocation failed - JavaScript heap out of memory

£可爱£侵袭症+ 提交于 2021-02-10 06:28:32

问题


I am working on a project which is developing with NextJs and ReactJs. Suddenly this project showing Allocation failed - JavaScript heap out of memory 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.

package.json

{
  "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"
  }
}

next.config.js

const webpack = require("webpack");
require("dotenv").config();

module.exports = {
  webpack: config => {
    config.node = {
      fs: 'empty'
    }

    const env = Object.keys(process.env).reduce((acc, curr) => {
      acc[`process.env.${curr}`] = JSON.stringify(process.env[curr]);
      return acc;
   }, {});

    config.plugins.push(new webpack.DefinePlugin(env));
    return config
  }
}

Error in Visual Code terminal

<--- Last few GCs --->

[4562:0x103e3b000]   161295 ms: Mark-sweep 2041.6 (2051.3) -> 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) -> 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


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x10072e699]
Security context: 0x3ecf281008a1 <JSObject>
    1: createElement(aka createElement) [0x3ecf3bee16f9] [/Users/pater/Desktop/personal-blog/node_modules/react/cjs/react.development.js:~727] [pc=0x1d716fb9bc21](this=0x3ecfe42004a9 <undefined>,0x3ecffb609dc1 <String[#3]: div>,0x3ecfe4f40389 <Object map = 0x3ecfdd48e531>,0x3ecfe42004a9 <undefined>)
    2: arguments adaptor frame: 2->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

来源:https://stackoverflow.com/questions/61402846/allocation-failed-javascript-heap-out-of-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!