es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Sigo recibiendo el error “JavaScript heap fuera de memoria” en Digital Ocean ejecutando Ubuntu 20.04 (LTS) x64 MERN Stack Next.js.

Entonces hice algunos cambios en mi sitio Next.js en Digital Ocean e intenté ejecutar sudo npm run build para construirlo, pero sigo recibiendo este error:

“`[230305:0x4a81f70] 83420 ms: Mark-sweep 485.9 (491.2) -> 485.7 (492.2) MB, 4015.7 / 1.8 ms (average mu = 0.099, current mu = 0.009) allocation failure scavenge might not succeed
[230305:0x4a81f70] 87013 ms: Mark-sweep 486.6 (492.2) -> 486.4 (492.7) MB, 3574.2 / 11.8 ms (average mu = 0.051, current mu = 0.004) allocation failure scavenge might not succeed

<--- JS stacktrace --->

==== JS stack trace =========================================
0: ExitFrame [pc: 0x140dc19]
1: StubFrame [pc: 0x140eaed]
Security context: 0x3b4afa0408d1
2: /* anonymous /(aka / anonymous /) [0x2c959140c6c9] [/home/Dylancougar/massnow-frontend/node_modules/next/dist/compiled/terser/bundle.min.js:~1] [pc=0x1f71ab556e46](this=0x0eeca6ec04b1 )
3: / anonymous /(aka / anonymous /) [0x2c959140c749] [/home/Dylancougar/massnow-frontend/node_modules/next/dist/compi…

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory
1: 0xa1a640 node::Abort() [node]
2: 0xa1aa4c node::OnFatalError(char const*, char const) [node]
3: 0xb9a62e v8::Utils::ReportOOMFailure(v8::internal::Isolate
, char const*, bool) [node]
4: 0xb9a9a9 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
5: 0xd57c25 [node]
6: 0xd582b6 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [node]
7: 0xd64b75 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
8: 0xd65a25 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
9: 0xd684dc v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
10: 0xd2eefb v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
11: 0x10714ce v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long, v8::internal::Isolate*) [node]
12: 0x140dc19 [node]
Aborted (core dumped)
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! frontend@1.0.0 build: next build
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the frontend@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/logs/2021-11-30T0118-debug.log


Algunos de los pasos que intenté para resolver este problema fueron eliminar el archivo package.lock y la carpeta node_modules y reinstalar esa carpeta. Intenté aumentar la memoria en la terminal. Intenté aumentarla a 8 GB `export NODE_OPTIONS=" --max-old-space-size=8192"`. Puedo ejecutar npm run build bien en mi PC sin problemas y no tenía problemas con este script la semana pasada en mi droplet de Digital Ocean. El problema apareció aparentemente de la nada ayer. Esto es lo que obtengo al ver el archivo de registro:

0 info it worked if it ends with ok
1 verbose cli [ ‘/usr/bin/node’, ‘/usr/bin/npm’, ‘run’, ‘build’ ]
2 info using npm@6.14.15
3 info using node@v12.22.7
4 verbose run-script [ ‘prebuild’, ‘build’, ‘postbuild’ ]
5 info lifecycle frontend@1.0.0~prebuild: frontend@1.0.0
6 info lifecycle frontend@1.0.0~build: frontend@1.0.0
7 verbose lifecycle frontend@1.0.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle frontend@1.0.0~build: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/Dylancougar/massnow-frontend/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
9 verbose lifecycle frontend@1.0.0~build: CWD: /home/Dylancougar/massnow-frontend
10 silly lifecycle frontend@1.0.0~build: Args: [ ‘-c’, ‘next build’ ]
11 silly lifecycle frontend@1.0.0~build: Returned: code: 134 signal: null
12 info lifecycle frontend@1.0.0~build: Failed to exec build script
13 verbose stack Error: frontend@1.0.0 build: next build
13 verbose stack Exit status 134
13 verbose stack at EventEmitter. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:314:20)
13 verbose stack at ChildProcess. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:314:20)
13 verbose stack at maybeClose (internal/child_process.js:1022:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
14 verbose pkgid frontend@1.0.0
15 verbose cwd /home/Dylancougar/massnow-frontend
16 verbose Linux 5.4.0-88-generic
17 verbose argv “/usr/bin/node” “/usr/bin/npm” “run” “build”
18 verbose node v12.22.7
19 verbose npm v6.14.15
20 error code ELIFECYCLE
21 error errno 134
22 error frontend@1.0.0 build: next build
22 error Exit status 134
23 error Failed at the frontend@1.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 134, true ]
“`

Y la versión de Node que estoy usando en Digital Ocean es v12.22.7. ¿Alguien sabría de cualquier otro paso que pueda intentar?

Tags:  , , , ,

Answer

  1. Avatar for davy.ai

    Parece que el mensaje de error indica un problema de falta de memoria en el heap de JavaScript, lo cual se puede solucionar aumentando el tamaño de la memoria. Ya ha intentado aumentar la memoria a 8 GB, pero no funcionó. Aquí hay algunas cosas más que puede probar:

    1. Aumentar aún más la memoria: Puede intentar aumentar la memoria a un valor más alto, como 12 GB o 16 GB. Para hacer esto, ejecute el siguiente comando:
      export NODE_OPTIONS="--max-old-space-size=16384"
      
    2. Intentar usar la bandera --no-optional: Algunos paquetes npm pueden tener dependencias opcionales que requieren más memoria para instalar. Puede intentar ejecutar el comando npm run build con la bandera --no-optional para omitir la instalación de estos paquetes:
      npm run build --no-optional
      
    3. Actualice npm y Node.js: Actualmente está utilizando la versión de npm 6.14.15 y la versión de Node.js 12.22.7. Intente actualizar ambos a las últimas versiones y vea si resuelve el problema:
      npm install -g npm
      sudo apt-get update && sudo apt-get upgrade nodejs
      
    4. Verificar las fugas de memoria: Si ninguna de las soluciones anteriores funciona, es posible que tenga una fuga de memoria en su código. Puede utilizar herramientas como Node.js Memory Profiling para encontrar y solucionar estas fugas.
      node --inspect myfile.js
      

    Espero que una de estas soluciones le ayude a resolver el problema.

Comments are closed.