- 
                Notifications
    You must be signed in to change notification settings 
- Fork 50
Closed
Description
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 lsoutput shows that most of the build outputs that should be present from the build are missing
- the build-2script fails because it’s missing required outputs frombuild-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-pluginto comment out theprocess.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.
Metadata
Metadata
Assignees
Labels
No labels
Projects
Status
No status