nuxt: nuxt generate FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
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.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 5
- Comments: 22 (6 by maintainers)
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:
The strange thing is that it doesn’t happen on a local machine, only within a Github Action environment. Using
NODE_OPTIONS: '--max_old_space_size=4096'within the.envof the Github Action worked and the issue is not happening anymore.Probably because GitHub Actions has a limit of 7Gb - see https://github.com/vitejs/vite/blob/main/.github/workflows/ci.yml#L4-L6 for example.
@danielroe https://stackblitz.com/edit/github-fsjrqu?file=nuxt.config.ts
seems like not having a
pages/index.vuefails thenpm run generatecommandso 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