Skip to content

fix(nextjs): Add sentry-cli existence check for enabling webpack plugin #4311

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() &&
Copy link
Member

@AbhiPrasad AbhiPrasad Dec 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have this check in the webpack plugin? I assume it'll also be a problem for @sentry/gatsby (which does similar things)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good point. Really we should have it in sentry-cli itself. I went ahead and implemented that, but it's currently blocked on unrelated rust errors, so I'm going to merge this in for now. Once those rust problems are fixed (and everyone, including me, is back from winter break), we can switch to that implementation.

(buildContext.isServer
? !userNextConfig.sentry?.disableServerWebpackPlugin
: !userNextConfig.sentry?.disableClientWebpackPlugin);

if (enableWebpackPlugin) {
// TODO Handle possibility that user is using `SourceMapDevToolPlugin` (see
Expand Down Expand Up @@ -296,3 +304,7 @@ export function getWebpackPluginOptions(

return { ...defaultPluginOptions, ...userPluginOptions };
}

function ensureCLIBinaryExists(): boolean {
return fs.existsSync(path.join(require.resolve('@sentry/cli'), '../../sentry-cli'));
}