getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.88k stars 1.55k forks source link

@sentry/nextjs Integration Causes Build Failure Due to "JavaScript Heap Out of Memory" #13331

Open trananhtung opened 1 month ago

trananhtung commented 1 month ago

Environment

SaaS (https://sentry.io/)

Steps to Reproduce

I am experiencing a build failure when integrating @sentry/nextjs into my Next.js project. The issue arises during the build process, resulting in a "JavaScript heap out of memory" error. Below are the relevant details:

My config

import { withSentryConfig } from '@sentry/nextjs';
// import bundleAnalyzer from '@next/bundle-analyzer';

// const withBundleAnalyzer = bundleAnalyzer({
//   enabled: process.env.ANALYZE === 'true',
// });

/** @type {import('next').NextConfig} */
const nextConfig = {
  swcMinify: true,
  productionBrowserSourceMaps: false,
  experimental: {
    serverSourceMaps: false,
  },
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'imagedelivery.net',
        port: '',
      },
    ],
  },
};

// export default nextConfig;

export default withSentryConfig(nextConfig, {
  // For all available options, see:
  // https://github.com/getsentry/sentry-webpack-plugin#options

  org: 'tat-team',
  project: 'designbyai_webapp',

  // Only print logs for uploading source maps in CI
  silent: true,

  authToken: process.env.SENTRY_AUTH_TOKEN,
});

Expected Result

I can normally build and run my next.js with the sentry.

Actual Result

getsentry/sentry#10 27.78 dependencies:
getsentry/sentry#10 27.78 + @kodingdotninja/use-tailwind-breakpoint 1.0.0
getsentry/sentry#10 27.78 + @next/third-parties 14.2.5
getsentry/sentry#10 27.78 + @paypal/react-paypal-js 8.5.0
getsentry/sentry#10 27.78 + @sentry/nextjs 8.25.0
getsentry/sentry#10 27.78 + @stripe/react-stripe-js 2.7.3
getsentry/sentry#10 27.78 + @stripe/stripe-js 4.2.0
getsentry/sentry#10 27.78 + clsx 2.1.1
getsentry/sentry#10 27.78 + copy-to-clipboard 3.3.3
getsentry/sentry#10 27.78 + file-saver 2.0.5
getsentry/sentry#10 27.78 + jwt-decode 4.0.0
getsentry/sentry#10 27.78 + lodash 4.17.21
getsentry/sentry#10 27.78 + next 14.2.5
getsentry/sentry#10 27.78 + query-string 9.1.0
getsentry/sentry#10 27.78 + react 18.3.1
getsentry/sentry#10 27.78 + react-dom 18.3.1
getsentry/sentry#10 27.78 + react-hook-form 7.52.2
getsentry/sentry#10 27.78 + react-icons 5.2.1
getsentry/sentry#10 27.78 + react-infinite-scroll-component 6.1.0
getsentry/sentry#10 27.78 + react-multi-carousel 2.8.5
getsentry/sentry#10 27.78 + react-slick 0.30.2
getsentry/sentry#10 27.78 + react-toastify 10.0.5
getsentry/sentry#10 27.78 + resize-observer-polyfill 1.5.1
getsentry/sentry#10 27.78 + sharp 0.33.4
getsentry/sentry#10 27.78 + slick-carousel 1.8.1
getsentry/sentry#10 27.78 + swr 2.2.5
getsentry/sentry#10 27.78 + zustand 4.5.4
getsentry/sentry#10 27.78 
getsentry/sentry#10 27.78 devDependencies:
getsentry/sentry#10 27.78 + @builder.io/partytown 0.10.2
getsentry/sentry#10 27.78 + @commitlint/cli 19.4.0
getsentry/sentry#10 27.78 + @commitlint/config-conventional 19.2.2
getsentry/sentry#10 27.78 + @tailwindcss/typography 0.5.14
getsentry/sentry#10 27.78 + @types/file-saver 2.0.7
getsentry/sentry#10 27.78 + @types/lodash 4.17.7
getsentry/sentry#10 27.78 + @types/node 20.14.15
getsentry/sentry#10 27.78 + @types/react 18.3.3
getsentry/sentry#10 27.78 + @types/react-slick 0.23.13
getsentry/sentry#10 27.78 + @typescript-eslint/eslint-plugin 7.18.0
getsentry/sentry#10 27.78 + autoprefixer 10.4.20
getsentry/sentry#10 27.78 + cssnano 7.0.5
getsentry/sentry#10 27.78 + daisyui 4.12.10
getsentry/sentry#10 27.78 + eslint 8.57.0
getsentry/sentry#10 27.78 + eslint-config-next 14.2.3
getsentry/sentry#10 27.78 + eslint-config-prettier 9.1.0
getsentry/sentry#10 27.78 + eslint-plugin-tailwindcss 3.17.4
getsentry/sentry#10 27.78 + husky 9.1.4
getsentry/sentry#10 27.78 + lint-staged 15.2.8
getsentry/sentry#10 27.78 + postcss 8.4.41
getsentry/sentry#10 27.78 + postcss-import 16.1.0
getsentry/sentry#10 27.78 + prettier 3.3.3
getsentry/sentry#10 27.78 + tailwindcss 3.4.9
getsentry/sentry#10 27.78 + typescript 5.4.5
getsentry/sentry#10 27.78 
getsentry/sentry#10 27.83 
getsentry/sentry#10 27.83 > designbyai_ui_daisy@0.1.0 prepare /usr/src/app
getsentry/sentry#10 27.83 > husky
getsentry/sentry#10 27.83 
getsentry/sentry#10 27.92 .git can't be foundDone in 27.5s
getsentry/sentry#10 DONE 28.6s
getsentry/sentry#11 [app 7/9] COPY . .
getsentry/sentry#11 DONE 5.9s
getsentry/sentry#12 [app 8/9] COPY .env.production .env
getsentry/sentry#12 DONE 0.1s
getsentry/sentry#13 [app 9/9] RUN pnpm run build
getsentry/sentry#13 1.679 
getsentry/sentry#13 1.679 > designbyai_ui_daisy@0.1.0 build /usr/src/app
getsentry/sentry#13 1.679 > next build
getsentry/sentry#13 1.679 
getsentry/sentry#13 4.654 Attention: Next.js now collects completely anonymous telemetry regarding usage.
getsentry/sentry#13 4.656 This information is used to shape Next.js' roadmap and prioritize features.
getsentry/sentry#13 4.657 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
getsentry/sentry#13 4.657 https://nextjs.org/telemetry
getsentry/sentry#13 4.657 
getsentry/sentry#13 4.878   ▲ Next.js 14.2.5
getsentry/sentry#13 4.878   - Environments: .env.production, .env
getsentry/sentry#13 4.879   - Experiments (use with caution):
getsentry/sentry#13 4.879     · instrumentationHook
getsentry/sentry#13 4.880 
getsentry/sentry#13 5.045    Creating an optimized production build ...
getsentry/sentry#13 11.49 (node:16) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
getsentry/sentry#13 11.49 (Use `node --trace-deprecation ...` to show where the warning was created)
getsentry/sentry#13 80.00 
getsentry/sentry#13 80.00 <--- Last few GCs --->
getsentry/sentry#13 80.00 
getsentry/sentry#13 80.00 [16:0x7c0e7bcc8000]    78206 ms: Scavenge 472.1 (486.8) -> 470.6 (486.8) MB, pooled: 8 MB, 2.39 / 0.00 ms  (average mu = 0.[157](https://github.com/ezzily/designbyai-webapp/actions/runs/10338763424/job/28617278827#step:3:158), current mu = 0.017) allocation failure; 
getsentry/sentry#13 80.00 [16:0x7c0e7bcc8000]    78213 ms: Scavenge 472.1 (486.8) -> 471.0 (487.3) MB, pooled: 7 MB, 1.70 / 0.00 ms  (average mu = 0.157, current mu = 0.017) allocation failure; 
getsentry/sentry#13 80.00 [16:0x7c0e7bcc8000]    78220 ms: Scavenge 472.6 (487.3) -> 471.3 (491.5) MB, pooled: 3 MB, 2.63 / 0.00 ms  (average mu = 0.157, current mu = 0.017) allocation failure; 
getsentry/sentry#13 80.00 
getsentry/sentry#13 80.00 
getsentry/sentry#13 80.00 <--- JS stacktrace --->
getsentry/sentry#13 80.00 
getsentry/sentry#13 80.00 FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
getsentry/sentry#13 80.00 ----- Native stack trace -----
getsentry/sentry#13 80.00 
getsentry/sentry#13 80.79  ELIFECYCLE  Command failed.
getsentry/sentry#13 ERROR: process "/bin/sh -c pnpm run build" did not complete successfully: exit code: 1
------
 > [app 9/9] RUN pnpm run build:
80.00 [16:0x7c0e7bcc8000]    78213 ms: Scavenge 472.1 (486.8) -> 471.0 (487.3) MB, pooled: 7 MB, 1.70 / 0.00 ms  (average mu = 0.157, current mu = 0.017) allocation failure; 
80.00 [16:0x7c0e7bcc8000]    78220 ms: Scavenge 472.6 (487.3) -> 471.3 (491.5) MB, pooled: 3 MB, 2.63 / 0.00 ms  (average mu = 0.157, current mu = 0.017) allocation failure; 
80.00 
80.00 
80.00 <--- JS stacktrace --->
80.00 
80.00 FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
80.00 ----- Native stack trace -----
80.00 
80.79  ELIFECYCLE  Command failed.
------
failed to solve: process "/bin/sh -c pnpm run build" did not complete successfully: exit code: 1
Error: Process completed with exit code 17.

Product Area

Issues

Link

No response

DSN

No response

Version

Docker node:22-alpine

getsantry[bot] commented 1 month ago

Assigning to @getsentry/support for routing ⏲️

lforst commented 1 month ago

Hi this seems like a duplicate of https://github.com/getsentry/sentry-javascript/issues/10468 - can you check it out? We can likely not troubleshoot this unless we get a memory profile or repro of some sort.