Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
safejace opened this issue Jun 15, 2022 · 22 comments

Comments

@safejace
Copy link

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.
@safejace
Copy link
Author

@danielroe
Copy link
Member

Thanks! Would you provide a reproduction? 🙏

@safejace
Copy link
Author

@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

@imrim12
Copy link

imrim12 commented Jun 19, 2022

Having the same issue when i upgrade to 3.0.0-rc.4, it was fine before

@mklueh
Copy link

mklueh commented Jun 27, 2022

Same here, but only in CI using GitHub Actions and using Netlify CLI to build, see https://github.com/nuxt/framework/discussions/1799#discussioncomment-3033754

@itslucylol
Copy link

Im having this issue both locally and with Cloudflare's automated build system on rc6

@danielroe
Copy link
Member

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: vitejs/vite#2433 (comment).

You might try disabling sourcemaps:

export default defineNuxtConfig({
  sourcemap: false
})

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
@madebyfabian
Copy link
Sponsor Collaborator

madebyfabian commented Feb 7, 2023

Not reproducable by @danielroe, welp, let's close this! Gotta bring that issue count down my nuxt friends 💚

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Feb 7, 2023
@Andrew0914
Copy link

Andrew0914 commented Feb 9, 2023

It is still happening, when run nuxt generate and in nuxt.config.js set 🤔

sourcemap: true

or

sourcemap: {
  client: true,
  server: false
}

My nuxt config:

import { sentryVitePlugin } from "@sentry/vite-plugin";

require("custom-env").env(true);

function removeDataTestAttrs(node: any, _context: any) {
  if (node.type === 1 /* NodeTypes.ELEMENT */) {
    node.props = node.props.filter((prop: any) =>
      prop.type === 6 /* NodeTypes.ATTRIBUTE */
        ? prop.name !== "data-testid"
        : true
    );
  }
}

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  dev: process.env.NODE_ENV !== "production",
  ssr: false,
  sourcemap: {
    client: true,
    server: false,
  },
  modules: ["@nuxtjs/i18n", "@pinia/nuxt"],
  components: [
    {
      path: "~/components/",
      pathPrefix: false,
    },
  ],
  i18n: {
    vueI18n: {
      legacy: false,
      locale: "en",
      messages: {
        // TODO: Verificar que sea la forma correcta de importar
        en: require("./locales/en.json"),
      },
    },
  },
  vite: {
    plugins: [
      {
        ...sentryVitePlugin({
          org: 'some',
          project: 'some',
          include: './dist',
          ignore: ['node_modules'] // Auth tokens can be obtained from https://sentry.io/settings/account/api/auth-tokens/
          // and needs the `project:releases` and `org:read` scopes
          //authToken: env.VITE_SENTRY_AUTH_TOKEN,
        }),
        apply(_config, _ctx) {
          return process.env.NODE_ENV !== 'development'
        }
      }
    ],
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: '@use "@/assets/css/app.scss" as *;',
        },
      },
    },
    define: {
      "window.global": {},
    },
    vue: {
      template: {
        compilerOptions: {
          nodeTransforms:
            process.env.NODE_ENV == "production" ? [removeDataTestAttrs] : [],
        },
      },
    },
  },
  router: {
    options: { hashMode: true },
  },
});

Error output:


<--- Last few GCs --->

[7032:0x614e570]    84441 ms: Scavenge (reduce) 2022.7 (2082.0) -> 2022.5 (2082.3) MB, 9.6 / 0.0 ms  (average mu = 0.418, current mu = 0.352) allocation failure; 
[7032:0x614e570]    86150 ms: Mark-sweep (reduce) 2024.3 (2083.8) -> 2024.1 (2084.5) MB, 1159.6 / 0.0 ms  (average mu = 0.386, current mu = 0.356) allocation failure; GC in old space requested


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0xb7b150 node::Abort() [node]
 2: 0xa8c89a  [node]
 3: 0xd62ea0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 4: 0xd63247 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 5: 0xf40945  [node]
 6: 0xf52e2d v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 7: 0xf2d52e v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 8: 0xf2e8f7 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 9: 0xf0faca v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
10: 0x12d357d v8::internal::Runtime_AllocateInOldGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
11: 0x17001f9  [node]
Aborted

I have to set sourcemap values as false in both cases in order to get work, but i need the sourcemaps to upload them to my sentry instance. 😢

@bangjelkoski
Copy link

Any update on this issue?

Copy link
Member

If you can provide a reproduction, we can reopen and investigate.

@bangjelkoski
Copy link

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 .env of the Github Action worked and the issue is not happening anymore.

@danielroe
Copy link
Member

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.

@toniengelhardt
Copy link
Contributor

I also get it building on Digital Ocean when I enable client source maps. Locally build works.

@Reidond
Copy link

Reidond commented May 23, 2023

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 .env of the Github Action worked and the issue is not happening anymore.

this helped me

@Abdulhai-Mohamed
Copy link

Any updates 😒

@SleepiestAdam
Copy link

We're also getting this error when trying to prerender our site. Setting NODE_OPTIONS="--max_old_space_size= 8192" doesn't appear to help at all.

@toniengelhardt
Copy link
Contributor

We're also getting this error when trying to prerender our site. Setting NODE_OPTIONS="--max_old_space_size= 8192" doesn't appear to help at all.

Not sure if this is a real fix or just coincidence, but I solved it in my case by reducing the --max_old_space_size flag to be less than the memory of the droplet + heap size (3072 in my case).

I know that for instance for postgres it just crashes if you reach the memory limit of the machine. Might this be a similar issue?

@dnndev
Copy link

dnndev commented Jul 2, 2023

For others who may be in my boat - (Nuxt 3.6.1). Even though I have 64GB memory and nothing else running, I got this error building locally for production as well as on Netlify. I noticed in my logs that the final .nuxt/dist/server/server.mjs file was about 20MB and the source map was about 25MB. I figured this may be why there was a memory allocation error.

I hadn't yet cleaned up my project for production. I had all the Font Awesome libraries available and all were being transpiled (as configured in nuxt.config.ts). I removed the unused libraries from the transpile section and removed their imports elsewhere in the app. This brought my .nuxt/dist/server/server.mjs file down to 5.9MB and map to 7.3MB. This was enough for the build to work locally and on Netlify.

I hope this helps someone, including my future self.

@bangjelkoski
Copy link

For others who may be in my boat - (Nuxt 3.6.1). Even though I have 64GB memory and nothing else running, I got this error building locally for production as well as on Netlify. I noticed in my logs that the final .nuxt/dist/server/server.mjs file was about 20MB and the source map was about 25MB. I figured this may be why there was a memory allocation error.

I hadn't yet cleaned up my project for production. I had all the Font Awesome libraries available and all were being transpiled (as configured in nuxt.config.ts). I removed the unused libraries from the transpile section and removed their imports elsewhere in the app. This brought my .nuxt/dist/server/server.mjs file down to 5.9MB and map to 7.3MB. This was enough for the build to work locally and on Netlify.

I hope this helps someone, including my future self.

Hey, how do you exclude libraries that you don't want to be transpiled?

@dnndev
Copy link

dnndev commented Jul 2, 2023

It's not excluding per se. It's simply removing them from the transpile block in defineNuxtConfig. So, for Font Awesome, the recommended setup is to include the libraries there. When setting up my project, I put all the libraries in there since I was not sure which styling I'd go with. So to "exclude" them, I just removed or commented them out.

Example:

export default defineNuxtConfig({
  devtools: { enabled: false },

  css: ['@fortawesome/fontawesome-svg-core/styles.css'],

  modules: ['@nuxtjs/tailwindcss', '@pinia/nuxt'],

  build: {
    transpile: [
      '@fortawesome/vue-fontawesome',
      '@fortawesome/fontawesome-svg-core',
      // '@fortawesome/free-brands-svg-icons',
      // '@fortawesome/free-regular-svg-icons',
      // '@fortawesome/free-solid-svg-icons',
      // '@fortawesome/pro-duotone-svg-icons',
      '@fortawesome/pro-light-svg-icons',
      '@fortawesome/pro-regular-svg-icons',
      // '@fortawesome/pro-solid-svg-icons',
      // '@fortawesome/pro-thin-svg-icons',
      // '@fortawesome/sharp-light-svg-icons',
      // '@fortawesome/sharp-regular-svg-icons',
      // '@fortawesome/sharp-solid-svg-icons',
    ],
  },
  runtimeConfig: {
    public: {
...

Above I've commented the libraries out. I'll remove them before production.

HTH,
Kelly

@TingYu-Lee
Copy link

TingYu-Lee commented Apr 9, 2024

Still have the same problem.

I tried changing the IconName of fontawesome-common-types/index.d.s from union type to string

  • pass

Is this union type related?

P.S
for copy

node_modules/@fortawesome/fontawesome-common-types/index.d.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests