Skip to content

fix(nextjs): Don't crash build when auth token is missing #7427

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
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
40 changes: 39 additions & 1 deletion packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,45 @@ export function getWebpackPluginOptions(

checkWebpackPluginOverrides(defaultPluginOptions, userPluginOptions);

return { ...defaultPluginOptions, ...userPluginOptions };
return {
...defaultPluginOptions,
...userPluginOptions,
errorHandler(err, invokeErr, compilation) {
// Hardcoded way to check for missing auth token until we have a better way of doing this.
if (err && err.message.includes('Authentication credentials were not provided.')) {
const warningPrefix = `${chalk.yellow('warn')} -`;

let msg;

if (process.env.VERCEL) {
msg = `To fix this, use Sentry's Vercel integration to automatically set the ${chalk.bold.cyan(
'SENTRY_AUTH_TOKEN',
)} environment variable: https://vercel.com/integrations/sentry`;
} else {
msg =
'You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/\n' +
`After generating a Sentry auth token, set it via the ${chalk.bold.cyan(
'SENTRY_AUTH_TOKEN',
)} environment variable during the build.`;
}

// eslint-disable-next-line no-console
console.error(
`${warningPrefix} ${chalk.bold(
'No Sentry auth token configured.',
)} Source maps will not be uploaded.\n${msg}\n`,
);

return;
}

if (userPluginOptions.errorHandler) {
return userPluginOptions.errorHandler(err, invokeErr, compilation);
}

return invokeErr();
},
};
}

/** Check various conditions to decide if we should run the plugin */
Expand Down