Open ricardomatias opened 1 month ago
Assigning to @getsentry/support for routing ⏲️
Hi @ricardomatias, does the build succeed locally without problems? Could you paste your next config here?
The issue in the context that I created is still there, but I've managed to get to a stage where I can build the application (albeit it's very slow). I recall disabling sourcemaps was the first change which resulted in a successful build. Now it works even with sourcemaps, but I cant recall all the steps I took during that journey. This is my next config at the moment, which works:
const nextConfig = {
webpack: (config, options) => {
config.module.rules.push({
test: /\.html/,
use: [
options.defaultLoaders.babel,
{
loader: 'html-loader',
},
],
})
return config
},
experimental: {
instrumentationHook: true,
serverActions: {
bodySizeLimit: '10mb',
},
},
};
export default withSentryConfig(withNextIntl(nextConfig), {
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options
org: "XXXX",
project: "XXXX",
telemetry: false,
// Only print logs for uploading source maps in CI
silent: false,
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: false,
// 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",
sourcemaps: {
disable: true
},
// Hides source maps from generated client bundles
hideSourceMaps: true,
// 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: false,
});
From what I've seen other users report is that memory consumption with sourcemaps enabled always seems to hover around 4GB, it could be that you get lucky with some builds even when sourcemaps are enabled.
Try setting NODE_OPTIONS=--max-old-space-size=SIZE
to something >2GB. The recommendation is 75% of the available space NODE_OPTIONS=--max-old-space-size=6144
. Node will not use most of your 8GB of heap without this. As you can see in the logs, it ran out of memory with around 2GB of memory.
Additionally, you may find that setting an explicit experimental.cpus
might help: https://github.com/vercel/next.js/issues/48352 I have seen next build
with 32 CPUs crash as it creates 32 workers that eat up all the memory and crash. Setting to 4 CPUs resolved this build issue for me; maybe setting it to 1 or 2 might help. But I would start with increasing the old space size first.
As an aside: you will likely benefit from setting --max-semi-space-size=
to something greater than the default 8/16mb (I have found 64mb) helps to reduce garbage collection pauses greatly but this is outside of the scope of your problem and something to experiment with.
@m-sanders that is some great input. Thank you very much!
@m-sanders I have been facing the same issue in Vercel (8GB container). I tried the cpu/workerThreads tuning, limiting next build
to 6GB but things are not good.
In our next config, only the main
branch get their source maps uploaded to Sentry, config below:
const isVercelProduction = process.env.VERCEL_GIT_COMMIT_REF === 'main';
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
instrumentationHook: true,
serverActions: {
bodySizeLimit: '2mb', // Bump body size limit from 1 to 2 mb
},
workerThreads: isVercelProduction ? false : undefined,
cpus: isVercelProduction ? 1 : undefined,
},
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: true,
},
};
const { withSentryConfig } = require('@sentry/nextjs');
// In development mode we don't use the Sentry configuration
// This allows us to use turbo mode locally
module.exports =
process.env.NODE_ENV === 'production' && isVercelProduction
? withSentryConfig(nextConfig, {
org: 'REDACTED',
project: 'REDACTED',
silent: true,
telemetry: false,
widenClientFileUpload: true,
hideSourceMaps: true,
disableLogger: true,
automaticVercelMonitors: true,
async headers() {
return [
{
source: '/:path*',
headers: [
{
key: 'Document-Policy',
value: 'js-profiling',
},
],
},
];
},
})
: nextConfig;
Not all builds fail, which I think it might be related to resource allocation at the moment of the build (something on the Vercel side of things).
Do you have any other recommendations here? My next option is disabling the upload completely from Vercel and creating a job in GHA that will build my project / upload assets to Sentry (I did that in the past in a previous job).
Thanks
We had the same issue on Render, builds were failing for exceeding 8GB, had to disable source maps.
Environment
SaaS (https://sentry.io/)
Steps to Reproduce
npx @sentry/wizard@latest -i nextjs
All options for enhancements were marked as off.
Expected Result
That I can build the NextJS application. This is happening in a VPS from Hetzner with 4 vCPUs and 8gb ram.
Actual Result
Product Area
Unknown
Link
No response
DSN
No response
Version
No response