question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nuxt generate FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

See original GitHub issue

Environment

Nuxt CLI v3.0.0-rc.4 Nuxt project info:


  • Operating System: Darwin
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-rc.3
  • Package Manager: yarn@1.22.17
  • Builder: vite
  • User Config: runtimeConfig, build, css, buildModules, modules, sanity, vite
  • Runtime Modules: @nuxtjs/sanity@1.2.2, @vueuse/nuxt@8.6.0
  • Build Modules: @pinia/nuxt@0.1.9, @safesoftware/safebase-vue/nuxt@0.4.0

Reproduction

yarn nuxt build

Describe the bug

when trying to generate my site i get javascript heap allocation errors.

it hangs on ℹ Initializing prerenderer for a long time

my devops colleague said he had it running for the hour, and it finally failed (see logs).

Additional context

No response

Logs

yarn run v1.22.18
$ nuxt build
Nuxt CLI v3.0.0-rc.4                                                                                                                                       17:15:59
ℹ Running with Sanity project XXXXXX (production).                                                                                             @nuxtjs/sanity 17:16:14
ℹ Vite client warmed up in 77349ms                                                                                                                         17:17:46
 
 WARN                                                                                                                                                      17:18:46
(!) Some chunks are larger than 500 KiB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/guide/en/#outputmanualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
 
ℹ Client built in 137160ms                                                                                                                                 17:18:46
ℹ Building server...                                                                                                                                       17:18:46
 
 WARN  @fortawesome/fontawesome-pro doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.
 
✔ Server built in 65079ms                                                                                                                                  17:19:51
✔ Generated public .output/public                                                                                                                    nitro 17:19:54
start Building server...                                                                                                                             nitro 17:19:54
 
 WARN  rollup-plugin-inject: failed to parse /code/safecom-fmeuc/.nuxt/dist/server/server.mjs. Consider restricting the plugin to particular files via options.include
 
 
 ERROR  Rollup error: Identifier 'useRuntimeConfig' has already been declared (Note that you need plugins to import files that are not JavaScript)   nitro 18:16:01
 
 
 ERROR  Identifier 'useRuntimeConfig' has already been declared (Note that you need plugins to import files that are not JavaScript)                       18:16:01
 
  at error (node_modules/rollup/dist/es/shared/rollup.js:1858:30)
  at Module.error (node_modules/rollup/dist/es/shared/rollup.js:12422:16)
  at Module.tryParse (node_modules/rollup/dist/es/shared/rollup.js:12799:25)
  at Module.setSource (node_modules/rollup/dist/es/shared/rollup.js:12704:24)
  at ModuleLoader.addModuleSource (node_modules/rollup/dist/es/shared/rollup.js:22178:20)
 
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:5
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
danielroecommented, Nov 2, 2022

However, I still cannot reproduce this with the updated reproduction.

But, I think we can tentatively suggest that this might be an issue with rollup, which takes a fair amount of memory when compiling. In the original issue reporter’s case, it’s not vite but the nitro rollup build, but still this issue is relevant: https://github.com/vitejs/vite/issues/2433#issuecomment-1262301699.

You might try disabling sourcemaps:

export default defineNuxtConfig({
  sourcemap: false
})
1reaction
safejacecommented, Jun 16, 2022

@danielroe https://stackblitz.com/edit/github-fsjrqu?file=nuxt.config.ts

seems like not having a pages/index.vue fails the npm run generate command

~/projects/github-fsjrqu 58s
❯ npm run generate
$ nuxt generate
Nuxt CLI v3.0.0-rc.4                                                                            10:42:05
ℹ Client built in 1671ms                                                                        10:42:11
ℹ Building server...                                                                            10:42:11
✔ Server built in 571ms                                                                         10:42:11
✔ Generated public .output/public                                                         nitro 10:42:11
ℹ Initializing prerenderer                                                                nitro 10:42:11
ℹ Vite client warmed up in 2972ms                                                               10:42:12
ℹ Prerendering 1 initial routes with crawler                                              nitro 10:42:14
  ├─ / (238ms) (Error: [404] Page not found: /)                                           nitro 10:42:14
✔ You can now deploy .output/public to any static hosting!                                      10:42:15
~

so the error is different than on my local repo… but maybe because the repo is bigger it just takes longer and therefor uses more memory trying to build

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuxt generate FATAL ERROR: Ineffective mark-compacts ...
vue. js - Nuxt generate FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory - Stack ...
Read more >
Common memory leak issues in nuxt.js
FATAL ERROR : Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory.
Read more >
Nuxt generate FATAL ERROR: Ineffective mark-compacts ...
Coding example for the question Nuxt generate FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory-nuxt.js.
Read more >
Allocation Failed - Javascript Heap Out Of Memory ( Nuxt Js)
I tried using v2.0.0 with my nextjs sample project and got a javascript error: near heap limit Allocation failed - JavaScript heap out...
Read more >
JavaScript heap out of memory - Snyk Support
This generally occurs on larger projects where the default amount of memory allocated by Node (1.5gb) is insufficient to complete the command successfully....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found