From d010ec5d63b31bab161613bebc84f07badd728fd Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Wed, 15 Dec 2021 11:47:23 -0800 Subject: [PATCH] make sure sentry-cli binary existis before enabling webpack plugin --- packages/nextjs/src/config/webpack.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 6a147acda69b..a7a03ea67c59 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -62,9 +62,17 @@ export function constructWebpackConfigFunction( newConfig.entry = async () => addSentryToEntryProperty(origEntryProperty, buildContext); // Enable the Sentry plugin (which uploads source maps to Sentry when not in dev) by default - const enableWebpackPlugin = buildContext.isServer - ? !userNextConfig.sentry?.disableServerWebpackPlugin - : !userNextConfig.sentry?.disableClientWebpackPlugin; + const enableWebpackPlugin = + // TODO: this is a hack to fix https://github.com/getsentry/sentry-cli/issues/1085, which is caused by + // https://github.com/getsentry/sentry-cli/issues/915. Once the latter is addressed, this existence check can come + // out. (The check is necessary because currently, `@sentry/cli` uses a post-install script to download an + // architecture-specific version of the `sentry-cli` binary. If `yarn install`, `npm install`, or `npm ci` are run + // with the `--ignore-scripts` option, this will be blocked and the missing binary will cause an error when users + // try to build their apps.) + ensureCLIBinaryExists() && + (buildContext.isServer + ? !userNextConfig.sentry?.disableServerWebpackPlugin + : !userNextConfig.sentry?.disableClientWebpackPlugin); if (enableWebpackPlugin) { // TODO Handle possibility that user is using `SourceMapDevToolPlugin` (see @@ -296,3 +304,7 @@ export function getWebpackPluginOptions( return { ...defaultPluginOptions, ...userPluginOptions }; } + +function ensureCLIBinaryExists(): boolean { + return fs.existsSync(path.join(require.resolve('@sentry/cli'), '../../sentry-cli')); +}