Skip to content

[NEXT] withSentryConfig is throwing error with custom webpack for version 7.13 during build  #6355

Closed as not planned
@ruchidh

Description

@ruchidh

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/nextjs

SDK Version

7.13.0

Framework Version

No response

Link to Sentry event

No response

Steps to Reproduce

Suddenly Build is failing for sentry config with next js having custom webpack , for the below code from the last 3 days . Please help on this

const configWithPwa = withPWA({
	assetPrefix: '/ega',
	extends: ['plugin:@next/next/recommended'],
	experimental: {
		nextScriptWorkers: true,
	},
	sentry: {
		hideSourceMaps: true,
		// for all available options visit https://github.com/getsentry/sentry-webpack-plugin#options
	},
	async redirects() {
		return [
			{
				source: '/tools/tracking/:id',
				destination: '/tools/tracking/details/:id',
				statusCode: 301,
			},
		];
	},
	webpack(config, { webpack }) {
		/*
		 * enabling Tree Shaking for sentry debug and sentry tracing
		 * because we are not using them in prod
		 * Reference: https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/tree-shaking/
		 */
		config.plugins.push(
			new webpack.DefinePlugin({
				__SENTRY_DEBUG__: false,
				__SENTRY_TRACING__: false,
			}),
		);
	
		return config;
	},
	pwa: {
		disable: process.env.NODE_ENV === 'development',
		dest: 'public',
		sw: 'ega-sw.js',
		register: false,
		// For caching we need to prefix urls with "/ega"
		manifestTransforms: [
			async manifestEntries => {
				const manifest = manifestEntries.map(m => {
					// This method is looping over all manifest entries and
					// prefixing /ega to it as service worker is running inside /ega repo
					if (!/^(?:[a-z]+:)?\/\//.test(m.url)) {
						m.url = `${m.url}`;
					}
					return m;
				});
				return { manifest, warnings: [] };
			},
		],
		// url for manifest.json is not handled in above function,
		// so added additional config to add url manually
		additionalManifestEntries: [{ url: '/ega/manifest.json', revision: null }],
	},
});

const sentryEnabledEnvs = ['production', 'staging',];
module.exports = sentryEnabledEnvs.includes(process.env.SYSTEM_ENV)
	? withSentryConfig(configWithPwa, { silent: true })
	: configWithPwa;
	

In the above code withSentryConfig(configWithPwa, { silent: true }) the build is failing and getting errors on production and staging server .

Expected Result

Build shoudl be passed

Actual Result

Screenshot 2022-12-01 at 1 23 43 PM

please ignore the variable TRACKING_API IS THE constant defined that I tried to get from next config, bcoz build is failing to it is throwing error.

If I remove the webpack code it works fine

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nextjsIssues related to the Sentry Nextjs SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions