Skip to content

NextJS Build hungs.. with sourcemap enabled #16259

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

Open
3 tasks done
softmarshmallow opened this issue May 12, 2025 · 6 comments
Open
3 tasks done

NextJS Build hungs.. with sourcemap enabled #16259

softmarshmallow opened this issue May 12, 2025 · 6 comments

Comments

@softmarshmallow
Copy link

softmarshmallow commented May 12, 2025

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

"@sentry/nextjs": "^9.17.0",

Framework Version

"next": "15.3.2", "react": "19.1.0",

Link to Sentry event

No response

Reproduction Example/SDK Setup

Image

I recently added sentry to my nextjs app.

{
      org: process.env.SENTRY_ORG,
      project: process.env.SENTRY_PROJECT,
      silent: !process.env.CI, // Only print logs for uploading source maps in CI
      widenClientFileUpload: false,
      sourcemaps: {
        disable:
          process.env.NODE_ENV === "development" ||
          process.env.VERCEL_ENV === "preview",
      },

      // Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
      // This can increase your server load as well as your hosting bill.
      // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
      // side errors will fail.
      tunnelRoute: "/monitoring",

      // Automatically tree-shake Sentry logger statements to reduce bundle size
      disableLogger: true,

      // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
      // See the following for more information:
      // https://docs.sentry.io/product/crons/
      // https://vercel.com/docs/cron-jobs
      automaticVercelMonitors: true,
    } satisfies SentryBuildOptions

The build speed is almost unusable, I think it's a bug.
As you can see,

  • production -> sourcemap on
  • preview -> sourcemap off

I've turned off the widenClientFileUpload for faster build, which does not resolve the issue.

Before sentry, it was about 5min for build on vercel,

After sentry

  • preview (sourcemap off) takes up to 7min (resonable)
  • production exceeds the max build duration 45min.

The build logs says,.

........
    ~/ff24b331-ad6e-4070-940f-aef956132cf6-274.js.map (debug id ff24b331-ad6e-4070-940f-aef956132cf6)
    ~/fff82f28-0ad6-47e8-8633-da46db4abc42-130.js.map (debug id fff82f28-0ad6-47e8-8633-da46db4abc42)
[@sentry/nextjs - Node.js] Info: Successfully uploaded source maps to Sentry

But after the "[@sentry/nextjs - Node.js] Info: Successfully uploaded source maps to Sentry"

no logs will appear, and hungs for the next 30mins, build fails.

what is happening?

Steps to Reproduce

repo: https://github.com/gridaco/grida (/editor)

pnpm why @sentry/webpack-plugin

pnpm why @sentry/webpack-plugin
Legend: production dependency, optional only, dev only

[email protected] /Users/softmarshmallow/Documents/Apps/grida/grida/editor (PRIVATE)

dependencies:
@sentry/nextjs 9.17.0
└── @sentry/webpack-plugin 3.3.1
@andreiborza
Copy link
Member

Hi @softmarshmallow, thanks for writing in.

Could you run npm why @sentry/webpack-plugin and paste the output?

@softmarshmallow
Copy link
Author

Hi @softmarshmallow, thanks for writing in.

Could you run npm why @sentry/webpack-plugin and paste the output?

Hi. Updated in original post

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 May 12, 2025
@andreiborza
Copy link
Member

Thanks!

Hm, I'm not really spotting anything unusual from this. Could you please try to provide a reproduction repo?

@zhyd1997
Copy link

Hi 👋

I thought the root cause was that there are some large files in the server bundle files that the Sentry SDK cannot handle.

https://www.zhyd1997.dev/blog/cal-dot-com-sentry-vercel-oom

Image

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 May 13, 2025
@andreiborza
Copy link
Member

andreiborza commented May 13, 2025

Thanks for helping out @zhyd1997, that's great writeup. This could very well be related to running out of memory, it's a known issue.

Here are some remedies that you could try before going the route of completely removing withSentry. The withSentry wrapper does more than just ensuring source maps upload so I recommend keeping it.

@zhyd1997
Copy link

zhyd1997 commented May 13, 2025

Hi @andreiborza

Yes, I have tried them all when resolving the issue for Cal.com.

Update your @sentry/nextjs package to the latest version.
Yes, I did it, no effect.
Increase Node.js memory limit: You can try increasing the memory limit for Node.js during the build process. Add this to your build command: NODE_OPTIONS="--max-old-space-size=8192" next build. This flag will increase the memory available to the node process to 8 GB. We have found that Next.js consumes around 4 GB in most cases. Decrease the size depending on your memory availability.

The Vercel container only has 8 GB RAM, I added --max-old-space-size=6144(75% of the container RAM). no effect when using withSentry, but make sense for sentry-cli.

Disable source maps entirely: As a last resort, you can disable source map generation completely

The Cal team needs the sourcemap to debug errors. BTW, it works without sourcemaps.


The withSentry wrapper does more than just ensuring source maps upload so I recommend keeping it.

Yes, I see, it will change the webpack config in next.config.js|ts, add webpack plugin, module rules, inject debug IDs, and so on, and finally use new SentryCli() to do Sentry release (uploading sourcemaps both for nodejs, edge, and client runtime).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

3 participants