Nuxt generate FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Asked Answered
A

3

18

I'm trying to nuxt generate my static (with dynamics url params) html pages. Here's my route config in the nuxt.config.js file

routes: function () {
      let domain = 'https://example.com'
      if (process.env.NUXT_ENV === 'dev' || process.env.NUXT_ENV === 'development') {
        domain = 'https://dev-example.com'
      }
      if (process.env.NUXT_ENV === 'local') {
        domain = 'http://localhost:3002'
      }
      let rooms = axios.get(domain + '/nuxt/rooms').then((res) => {
        if(res && res.data.length){
          return res.data.map((room) => {
            return '/manage/pro/room/' + room._id
          })
        }else{
          return []
        }
      }).catch(response => {
        console.log('errore room')
      });
      let bookings = axios.get(domain + '/nuxt/users').then((res) => {
        if(res && res.data.length){
          return res.data.map((user) => {
            return '/bookings/' + user.slug
          })
        }else {
          return []
        }
      }).catch(response => {
        console.log('errore rehearsal')
      });
      let user = axios.get(domain + '/nuxt/users').then((res) => {
        if(res && res.data.length){
          return res.data.map((user) => {
            return '/user/' + user._id + '/' + user.username
          })
        }else {
          return []
        }
      }).catch(response => {
        console.log('errore user public')
      });
      let posts = axios.get(domain + '/nuxt/posts').then((res) => {
        if(res && res.data.length){
          return res.data.map((post) => {
            return '/post/' + post._id
          })
        }else {
          return []
        }
      }).catch(response => {
        console.log('errore posts')
      });
      return Promise.all([rooms, posts, user, bookings]).then(values => {
        return values.join().split(',');
      })
    }
  },

It' has been always good and the process succeded well till today. Which it seems to require too much RAM memory. Don't know why and don't know how to fix this issue. Here's the last console output lines

2018-09-06T13:12:34.423Z nuxt:render Rendering url /manage/pro/room/5b3f26783e62155502337f8f

<--- Last few GCs --->

[14687:0x2c19ac0]   657918 ms: Mark-sweep 1339.9 (1440.7) -> 1328.1 (1440.2) MB, 2760.7 / 0.1 ms  (average mu = 0.224, current mu = 0.161) allocation failure scavenge might not succeed
[14687:0x2c19ac0]   661179 ms: Mark-sweep 1341.0 (1440.2) -> 1330.6 (1444.2) MB, 2752.4 / 0.1 ms  (average mu = 0.191, current mu = 0.156) allocation failure scavenge might not succeed


<--- JS stacktrace --->

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

    0: ExitFrame [pc: 0x5b702a041bd]
    1: StubFrame [pc: 0x5b702a14fb2]
Security context: 0x3e9218f9e589 <JSObject>
    2: rules [0x2590b4e7c449] [/node_modules/clean-css/lib/writer/helpers.js:~46] [pc=0x5b704716ec9](this=0x3e348f706519 <JSGlobal Object>,context=0x1a44edae1691 <Object map = 0x169e1dc614d1>,tokens=0x1806c1ded131 <JSArray[2]>)
    3: all [0x2590b4e7c749] [/node_modules/clean-css/lib...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x89375c [node]
 3: v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 5: 0xe616b2 [node]
 6: v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
 7: v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 8: v8::internal::Heap::AllocateRawWithRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [node]
 9: v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [node]
10: v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [node]
11: 0x5b702a041bd
Asbestosis answered 6/9, 2018 at 13:44 Comment(0)
C
16

Edit your package.json and modify your start script to use node with --max-old-space-size=4096 flag for example, your package.json may have the following:

"scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start"
}

Use this instead:

"scripts": {
    "dev": "node --max-old-space-size=4096 node_modules/nuxt/bin/nuxt.js nuxt",
    "build": "node --max-old-space-size=4096 node_modules/nuxt/bin/nuxt.js build",
    "start": "node --max-old-space-size=4096 node_modules/nuxt/bin/nuxt.js start"
}

Some reference: https://medium.com/@vuongtran/how-to-solve-process-out-of-memory-in-node-js-5f0de8f8464c

Construct answered 11/12, 2018 at 0:23 Comment(3)
"dev": "node --max-old-space-size=4096 node_modules/nuxt/bin/nuxt.js nuxt" does not work. "dev": "node --max-old-space-size=4096 node_modules/nuxt/bin/nuxt.js" does :) For anyone strugglingNadean
the answer above (almost) works for me with 2k+ products. scripts also needs: "generate": "node --max-old-space-size=4096 node_modules/nuxt/bin/nuxt.js generate"Hemphill
Getting an error node:internal/modules/cjs/loader:1147 throw err; ^ Error: Cannot find module 'E:\Code\countersbd\frontend\tms-frontend\node_modules\nuxt\bin\nuxt.js' at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15) at Module._load (node:internal/modules/cjs/loader:985:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) at node:internal/main/run_main_module:28:49 { code: 'MODULE_NOT_FOUND', requireStack: [] }Cambric
M
0

This might be caused by an infinite loop. In my case a misconfigured environment variable pointed to the Nuxt server's port at localhost instead of another service.

See more common causes here:

Marsland answered 18/8, 2022 at 13:49 Comment(0)
P
0
"generate": "node --max-old-space-size=8096 node_modules/nuxi/bin/nuxi.mjs generate",
Paraphernalia answered 3/7 at 0:36 Comment(1)
While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions applyImago

© 2022 - 2024 — McMap. All rights reserved.