Skip to content

Since 3.0.0, Sentry webpack plugin aborts build processes prematurely, breaking builds #662

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

Closed
controversial opened this issue Jan 23, 2025 · 4 comments · Fixed by #663
Closed
Assignees

Comments

@controversial
Copy link

controversial commented Jan 23, 2025

Environment

sentry/[email protected]

Steps to Reproduce

I use @sentry/webpack-plugin directly in my Next.js config, rather than using the parent function from @sentry/nextjs:

next.config.ts looks like:

import { sentryWebpackPlugin } from '@sentry/webpack-plugin';
import { getWebpackPluginOptions as getSentryWebpackPluginOptions } from '@sentry/nextjs/config/webpackPluginOptions';
import * as Sentry from '@sentry/nextjs';

export default {
  webpack(config, buildContext) => {
    const { isServer, dev: isDev, webpack } = buildContext;

    // Sentry webpack plugin uploads source maps
    if (!isDev && process.env.CI) {
      config.devtool = isServer ? 'source-map' : 'hidden-source-map';
      (config.plugins ??= []).push(new webpack.DefinePlugin({
        __SENTRY_RELEASE__: JSON.stringify(Sentry.getSentryRelease()),
      }));
      const sentryPluginInstance = sentryWebpackPlugin(getSentryWebpackPluginOptions(buildContext, {
        org: 'my-org',
        project: 'my-project',
        sentryUrl: 'https://sentry.io',
        authToken: process.env.SENTRY_AUTH_TOKEN,

        silent: true,
        widenClientFileUpload: true,
        hideSourceMaps: true,
      }));
      config.plugins.push(sentryPluginInstance);
    }

    return config;
  },

  experimental: {
    typedRoutes: true,
    authInterrupts: true,

    webpackBuildWorker: true,
    parallelServerCompiles: true,
    parallelServerBuildTraces: true,
    webpackMemoryOptimizations: true,
  },
};

Add a build script:

    "build-1": "echo 'build 1' && next build --experimental-build-mode compile && ls -l .next",
    "build-2": "echo 'build 2' && next build --experimental-build-mode generate",
    "build": "npm run build-1 && npm run build-2",

Expected Result

The project builds and uploads source maps to Sentry. The output should look something like:

build 1
   ▲ Next.js 15.1.6
...
   Creating an optimized production build ...
...
 ✓ Compiled successfully
 ✓ Collecting page data    
 ✓ Collecting build traces    
 ✓ Finalizing page optimization    

total 1072
-rw-r--r--   1 luke  staff      21 Jan 23 18:23 BUILD_ID
-rw-r--r--   1 luke  staff   33450 Jan 23 18:23 app-build-manifest.json
-rw-r--r--   1 luke  staff    4656 Jan 23 18:23 app-path-routes-manifest.json
-rw-r--r--   1 luke  staff     996 Jan 23 18:23 build-manifest.json
drwxr-xr-x   5 luke  staff     160 Jan 23 15:13 cache
drwxr-xr-x   4 luke  staff     128 Jan 23 18:22 diagnostics
-rw-r--r--   1 luke  staff      93 Jan 23 18:23 export-marker.json
-rw-r--r--   1 luke  staff     515 Jan 23 18:23 images-manifest.json
-rw-r--r--   1 luke  staff   12217 Jan 23 18:23 next-minimal-server.js.nft.json
-rw-r--r--   1 luke  staff   54725 Jan 23 18:23 next-server.js.nft.json
-rw-r--r--   1 luke  staff      20 Jan 23 18:22 package.json
-rw-r--r--   1 luke  staff     312 Jan 23 18:23 prerender-manifest.json
-rw-r--r--   1 luke  staff       2 Jan 23 18:23 react-loadable-manifest.json
-rw-r--r--   1 luke  staff    6688 Jan 23 18:23 required-server-files.json
-rw-r--r--   1 luke  staff    9938 Jan 23 18:23 routes-manifest.json
drwxr-xr-x  24 luke  staff     768 Jan 23 18:23 server
drwxr-xr-x   6 luke  staff     192 Jan 23 18:23 static
-rw-r--r--   1 luke  staff  330441 Jan 23 18:23 trace
drwxr-xr-x   6 luke  staff     192 Jan 23 18:22 types

build 2
   ▲ Next.js 15.1.6
   Creating an optimized production build ...
   Collecting page data ...
...

Actual Result

The project does not build; the build-1 process exits with a success error code before the project has actually been built

build 1
    ▲ Next.js 15.1.6
...
   Creating an optimized production build ...

total 8
drwxr-xr-x 4 root root   67 Jan 23 22:22 cache
drwxr-xr-x 2 root root   58 Jan 23 22:21 diagnostics
-rw-r--r-- 1 root root   20 Jan 23 22:21 package.json
drwxr-xr-x 6 root root 4096 Jan 23 22:23 server
drwxr-xr-x 3 root root   77 Jan 23 22:22 types

build 2

> Build error occurred
[Error: ENOENT: no such file or directory, open '/vercel/path0/packages/matchbox.marriagepact.com/.next/BUILD_ID'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/vercel/path0/packages/matchbox.marriagepact.com/.next/BUILD_ID'
}
error: script "build-2" exited with code 1
ERROR: command finished with error: command (/vercel/path0/packages/matchbox.marriagepact.com) /bun1/bun run build-2 exited (1)
command (/vercel/path0/packages/matchbox.marriagepact.com) /bun1/bun run build-2 exited (1)

Note:

  • the build process exits after “Creating an optimized production build”; the subsequent steps are never logged
  • The ls output shows that most of the build outputs that should be present from the build are missing
  • the build-2 script fails because it’s missing required outputs from build-1

The sentry plugin exits the build-1 process, which causes the subsequent steps of the build to fail completely as they are missing the files that were to be generated after the process was exited by Sentry

Cause

Presumably this is caused by #653

  • I have confirmed that patching @sentry/webpack-plugin to comment out the process.exit(0) lines added in fix(webpack): Ensure process exits when done #653 resolves this issue for me and allows the build to proceed normally.
  • I don’t know why using process.exit() to terminate the build process was considered reasonable/safe; afaik this is not normal behavior for a webpack plugin.
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 23, 2025
@Lms24
Copy link
Member

Lms24 commented Jan 24, 2025

Hey @controversial thanks for writing in! Seems like I was right to worry about #653. We'll find a fix ASAP.

I don’t know why using process.exit() to terminate the build process was considered reasonable/safe;

I think the PR description of #653 describes this fairly well. Again, we'll fix this. Thanks for raising.

@Lms24
Copy link
Member

Lms24 commented Jan 24, 2025

The fix was released with 3.1.0. Let me know if the plugin still exits too early, thanks!

@controversial
Copy link
Author

controversial commented Jan 24, 2025

Thanks for getting on the fix so quickly! I’m sorry for my tone in the original issue; I was writing it in a rush and didn’t mean to come across as rude.

@controversial
Copy link
Author

Confirming 3.1.0 fixes the issue for me. I appreciate your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
2 participants