sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Memory leak with nuxt build

Open SwartZCoding opened this issue 7 months ago • 5 comments

Is there an existing issue for this?

  • [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [x] I have reviewed the documentation https://docs.sentry.io/
  • [x] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nuxt

SDK Version

"@sentry/browser": "^9.25.1",
"@sentry/nuxt": "^9.19.0",

Framework Version

nuxt 3.16.2

Link to Sentry event

No response

Reproduction Example/SDK Setup

Hello guys ! Since i have installed sentry on my nuxt project. My github action run out of memory...

I think this is the same issue of but on nextjs : https://github.com/getsentry/sentry-javascript/issues/12317

I have already try to increase on my actions the NODE_OPTIONS=--max_old_space_size=8192

My sentry client config :

import * as Sentry from "@sentry/nuxt";

Sentry.init({ // If set up, you can use your runtime config here // dsn: useRuntimeConfig().public.sentry.dsn, dsn: "",

// We recommend adjusting this value in production, or using tracesSampler // for finer control tracesSampleRate: 1.0,

// Setting this option to true will print useful information to the console while you're setting up Sentry. debug: false,

beforeSend(event, hint) { const error = hint.originalException; if ( error && typeof error.message === 'string' && error.message.includes("window.webkit.messageHandlers") ) { return null; // ignore } return event; } });

Config on nuxt.config :

sentry: { sourceMapsUploadOptions: { org: 'XXXXX', project: 'XXXXX', authToken: "XXXX", } },

sourcemap: { client: 'hidden' }

Steps to Reproduce

  1. Create a nuxt project
  2. setup a sentry into it
  3. Try to build it with github actions

Expected Result

Don't get out of memory...

Actual Result

[6/6] RUN npm run build: 127.9 <--- JS stacktrace ---> 127.9 127.9 FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 127.9 ----- Native stack trace ----- 127.9 159.4 npm error path /app/front 159.4 npm error command failed 159.4 npm error signal SIGABRT

SwartZCoding avatar Jun 04 '25 11:06 SwartZCoding

Hello, please only install the @sentry/nuxt SDK as it uses the browser SDK under the hood and it ensures that all SDKs are installed with the same version. Different versions could lead to unexpected issues. While I think the version mismatch is not the cause here, can you still try if this already fixes the problem?

Memory issues could also occur because of source maps generation. If you disable source maps generation on the server with false, do you still experience the memory leak?

s1gr1d avatar Jun 04 '25 13:06 s1gr1d

Hello, please only install the @sentry/nuxt SDK as it uses the browser SDK under the hood and it ensures that all SDKs are installed with the same version. Different versions could lead to unexpected issues. While I think the version mismatch is not the cause here, can you still try if this already fixes the problem?Memory issues could also occur because of source maps generation. If you disable source maps generation on the server with false, do you still experience the memory leak?

Hi ! Just try to reinstall sentry only the nuxt sdk and the error still happened.

I have try with same config, i got out of memory.

If i disabled server: false into sourcemap config in nuxt.config.ts it's seems to work. But with this param, i'm gonna lost all my sourcemap to identify issue no ?

SwartZCoding avatar Jun 04 '25 13:06 SwartZCoding

Then it's probably related to source maps. Nitro creates a very big chunk which creates a large source map in memory. Currently, there is no good way of chunking source maps. It's a general problem with the source map spec itself. You can read more here: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/683#issuecomment-2753598404

But you are right, setting sourcemap: false would disable source map generation for you. Do you have a very large project?

s1gr1d avatar Jun 05 '25 08:06 s1gr1d

Then it's probably related to source maps. Nitro creates a very big chunk which creates a large source map in memory. Currently, there is no good way of chunking source maps. It's a general problem with the source map spec itself. You can read more here: getsentry/sentry-javascript-bundler-plugins#683 (comment)

But you are right, setting sourcemap: false would disable source map generation for you. Do you have a very large project?

I don’t think it’s a very big project. But yes it’s a saas project.

SwartZCoding avatar Jun 05 '25 09:06 SwartZCoding

We'll come back to you if there are any updates on this. For the time being, you can also subscribe to the other issue in the bundler plugins related to this.

s1gr1d avatar Jun 05 '25 15:06 s1gr1d

A new PR was merged to the bundler plugins: https://github.com/getsentry/sentry-javascript-bundler-plugins/pull/761

This PR adds some build-time improvements and can help here. I will close the issue now. In case it's still a problem, we can always re-open it.

The Nuxt SDK uses the bundler plugins under the hood, so you don't need to explicitly install them. The change will be reflected when updating @sentry/nuxt to v10.

s1gr1d avatar Aug 04 '25 14:08 s1gr1d